5

I was setuping my project when saw this on @NotNull annotation in my DTOs

Not 'javax.validation.constraints.NotNull' but 'org.jetbrains.annotations.NotNull' would be used for code generation

I have import javax.validation.constraints.NotNull;

But still see this warning.

Why IDEA dont want to use javax NotNull and what should I do to force it?

Anton Kolosok
  • 482
  • 9
  • 24

2 Answers2

6

When you compile your project, the IDE adds assertions to all methods and parameters annotated with the @NotNull annotation. The assertions will fail if null is passed in code where @NotNull is expected. You can disable this option and configure the list of annotations in the Settings/Preferences dialog Ctrl+Alt+S. Go to Build, Execution, Deployment | Compiler.

https://www.jetbrains.com/help/idea/nullable-and-notnull-annotations.html

Maybe this would to the trick.

maio290
  • 6,440
  • 1
  • 21
  • 38
  • This explains how to get rid of the error, not why IntelliJ IDEA doesn't want to use Javax's version of @NotNull – moffeltje Aug 05 '22 at 07:49
  • @moffeltje Well, it's obviously a feature of the IDE. Either it's replacing the `@NotNull` annotation with it's proprietary version or it's just a simple case of namespace pollution. Maybe annotating with the canonical name `@javax.validation.constraints.NotNull` would also fix this. If you are so interested into the why, you could take a look at the Community Edition's GIT repository and find out yourself. But I doubt that there will be a meaningful return on your time invest. – maio290 Aug 05 '22 at 11:38
0

In addition to maio290 's answer, it's important you change the "annotiation used for code generation" setting: screenshot of configure nullability/nonnull annotatioons dialog

Peter Wippermann
  • 4,125
  • 5
  • 35
  • 48