Configure IntelliJ to show warnings for Lombok's @NonNull

gdaniel

Gwendal Daniel

Posted on July 21, 2020

Configure IntelliJ to show warnings for Lombok's @NonNull

Lombok is a library I like to use in my projects to limit boilerplate code and focus on the core logic of my applications. I am using the IntelliJ plugin to integrate Lombok annotation processing with my IDE, for example to enable auto-completion of methods generated from @Getter/@Setter.

While this works pretty well, I regularly find myself searching resources on how I can configure Intellij to show warnings when I provide a null value to a method argument annotated with @NonNull. Since a picture is worth a thousand words here is what I try to achieve:

Missing warning in IntelliJ Editor

Since I spent some time figuring this out today I'll post my solution here in case anyone is wondering how this can be done (and also as an archive I can retrieve later 😅):

  • Open File -> Settings
  • Navigate to Editor -> Inspection -> Java -> Probable bugs -> Nullability problems -> @NotNull/@Nullable problems
  • Click on Configure Annotations in the right panel
  • Add lombok.NonNull in the NotNull annotations list
  • Rebuild your project

You should now see the warnings in your editor
IntelliJ printing the warning with Lombok annotation

You may have noticed the naming error in the warning pop-up ("@NotNull" instead of "@NonNull"). I didn't look into it, let me know if you have a solution for that!

💖 💪 🙅 🚩
gdaniel
Gwendal Daniel

Posted on July 21, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related