1

I just updated my project to use Spring Boot 2.0.3 with Spring Framework 5.0.7.

And now I see that some parameters in methods of MessageSource are annotated with Spring's shiny new @Nullable annotation. But due to this annotation, IDEA 14 says that the appropriate parameters cannot be null (SURPRISE!).

As I understand that's due to the fact that @Nullable is annotated with @Nonnull:

@Nonnull(
    when = When.MAYBE
)

What was the reason to mark annotation with a logically opposite one?

stepio
  • 865
  • 2
  • 9
  • 22
  • 1
    My quick guess is, that Spring and IDEA have different interpretations of "when". To find out who's right, or wrong, you'd want to look into the specification of `javax.annotation.Nonnull.when` but since this is based on a dead JSR you won't have much luck searching for any official specification. – Stephan Herrmann Jul 01 '18 at 14:27

1 Answers1

0

As explained by @StephanHerrmann, it's related to the original JSR. So the idea is that null value is allowed in some cases - just to make code self-documented. Similar approach is actually used in javax.annotation.Nullable:

@Documented
@TypeQualifierNickname
@Nonnull(when = When.UNKNOWN)
@Retention(RetentionPolicy.RUNTIME)
public @interface Nullable {

}

In latest IDEA versions this annotation is supported (or WILL be supported) out of the box. To fix IDEA warning in older versions you just need to add the Spring's annotation manually.

stepio
  • 865
  • 2
  • 9
  • 22