typetools / typetools/checker-framework
Inconsistent default nullability between Called Methods and Nullness checkers with Lombok
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 440
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 134
Description
The called methods checker has rudimentary support for Lombok, and it's fantastic. But, some coworkers of mine were recently bitten by this behavior:
A
@CalledMethodsannotation is placed on the receiver of the build() method, indicating the setter methods that must be invoked on the builder before callingbuild(). For Lombok, this annotation’s argument is the set of@lombok.NonNullfields that do not have default values.
https://checkerframework.org/manual/#called-methods-framework-details
The second sentence disagrees with the usual rules for nullness, where fields are assumed non-null unless annotated otherwise.
Concretely, it is easy to write code that creates null pointer exceptions even when both the Called Methods and Nullness checkers are enabled:
package misc;
import lombok.Builder;
import lombok.Value;
public class BuilderNullness {
@Value
@Builder
static class Data {
String value;
}
public static void main(String[] args) {
var data = Data.builder().build();
System.out.println(data.value.hashCode());
}
}
Output:
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "String.hashCode()" because "data.value" is null
at misc.BuilderNullness.main(BuilderNullness.java:16)
Adding an explicit @lombok.NonNull annotation to the String value field is the only way to get the expected compile-time error message:
BuilderNullness.java:[16,39] error: [finalizer.invocation] This finalizer cannot be invoked, because the following methods have not been called: value()
I suspect this policy was chosen to reduce false positives, but I would suggest that the default behavior should align with the nullness checker (fields are non-null unless annotated otherwise).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Called Methods checker’s Lombok support and the Called Methods framework details in the linked manual section. Reproduce the BuilderNullness example with both Called Methods and Nullness checking enabled, then trace how an unannotated Lombok field is classified. Done means the default nullability behavior is aligned or the intended policy is documented and covered by a regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100