You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using Checker Framework v3.22.2, Java 17, and the nullness checker, I get:
java: [dereference.of.nullable] dereference of possibly-null reference foo.bar()
Expectations
Record components are implicitly final, so the value of bar() is consistent across invocations. The checker should be able to infer this.
While the issue arises due to treatment of record components as methods, the typical behaviour is similar to accessing a final field, which behaves as one would expect. The exception is where components are overridden, where a developer may introduce impure or external effects.
Given
Using Checker Framework v3.22.2, Java 17, and the nullness checker, I get:
Expectations
Record components are implicitly final, so the value of
bar()
is consistent across invocations. The checker should be able to infer this.While the issue arises due to treatment of record components as methods, the typical behaviour is similar to accessing a final field, which behaves as one would expect. The exception is where components are overridden, where a developer may introduce impure or external effects.
Alternatives
Multiple workarounds already exist:
foo.bar()
to a variable:bar()
to annotate it as@Pure
:The text was updated successfully, but these errors were encountered: