3

How can I configure IntelliJ IDEA to give me warnings when the @NotNull / @Nullable contract is violated in Lombok's generated constructors?

I enabled the Settings* > Editor > Inspections > Java > Probable bugs > @NotNull/@Nullable problems inspection, and set the NotNull annotation to lombok.NonNull in the Settings > Editor > Inspections > Java > Probable bugs > @NotNull/@Nullable problems > Configure annotations setting.

configuring the @NotNull/@Nullable problems setting

IntelliJ IDEA:

  • gives warnings when null contract for Lombok getters and setters are violated
  • also gives warnings when null contract for RegularDataClass constructor is violated
  • but it doesn't give warnings when null contract for lombok constructors are violated...

showing lack of warning in IntelliJ

Eric
  • 16,397
  • 8
  • 68
  • 76
  • 1
    Deleted my answer since it wasn't entirely correct. It still appears to be an issue with IntelliJ, but I'm not sure how. I'd say it might be worth [reporting this to JetBrains](https://www.jetbrains.com/help/idea/reporting-issues-and-sharing-your-feedback.html). It seems that it's correctly processing the generated setter's `@NonNull` annotation on the parameter _after_ source generation, but it's not doing that for the constructor. The `RegularDataObject` probably works because it's already on the constructor at compile-time, so it gets processed correctly. – Brian Mar 06 '18 at 20:47
  • 1
    Also, if you do raise an issue in YouTrack, feel free to add it as a link either in a comment here on your question, or use the answer button below to [answer your own question](https://stackoverflow.com/help/self-answer). – Brian Mar 06 '18 at 20:49
  • 1
    This is an issue with the Lombok plugin, which does not reflect the property annotations onto the generated constructors. The Lombok plugin is not built or supported by JetBrains, so please don't report a YouTrack issue - contact the plugin developers instead. – yole Mar 06 '18 at 20:54

0 Answers0