Add a lombok.builder.build.nonNullAnnotation or similar to allow IDE "Null Analysis"

115 views
Skip to first unread message

Lorenzo Puglioli

unread,
Jan 10, 2023, 1:25:38 PM1/10/23
to Project Lombok
When using @Builder annotation the generated ".build()" method returns a value that surely cannot be null.

But the IDE doesn't know that, and, if the "Null Analysis" is enabled, the generated object will be treated as "potentially null".

Unfortunately, the "Non Nullable" annotation is not a java standard, and you can configure the IDE in different ways. For example, in some projects I use spring "org.springframework.lang.NonNull" annotation for that purpose.

So, lombok cannot add automatically this annotation.
I propose to add a specific entry on Lombok Configuration System to let the developer specify a custom annotation to add to generated code.
If the configuration is not present, no annotation will be emitted, on the contrary, the specified one will added to generated code.

Is this a reasonable request? Is it feasible?

Thanks - Lorenzo

Lorenzo Puglioli

unread,
Jan 11, 2023, 5:11:55 AM1/11/23
to Project Lombok
I relaunch my own proposal.
I realized that this feature can be much more general, not limited to @Builder pattern. A custom "NotNull" annotation can be automatically added in all cases in which the non-nullability is for some reason guaranteed (return values, getters).
Also, the feature can be even more aggressive, maybe optionally: in case of use of the built-in lombok @NonNull, the non nullability runtime checks on input parameters can be totally skipped from generated code and replaced by the annotation used by IDE null analysis
Reply all
Reply to author
Forward
0 new messages