Alternative for the depracted `@CheckForNull` annotation?

Please provide

  • Operating system: Windiows 10
  • SonarLint plugin version: 9.3
  • Programming language you’re coding in: Java
  • Is connected mode used: Not yet
    • Connected to SonarCloud or SonarQube (and which version):

And a thorough description of the problem / question:


As you can see in my attached image, the @CheckForNull dos work and SonarLint recognizes the situation correctly and does provide a potential NullPointerExpception warning.

The annotation comes from: import edu.umd.cs.findbugs.annotations.CheckForNull;

Unfortunately, this annotation is already deprecated.
So I want to ask what can I use instead in this situation to provoke the same effect?
I am grateful for any help!

Best regards

Hello @Abegail_Bar,

Thank you for asking for our help on this situation. Typically, when a library deprecates an annotation, method, or class, it also suggests the replacement; unfortunately, it’s not the case for edu.umd.cs.findbugs.annotations.CheckForNull.

The topic of which nullability annotation to use is controversial and there is no current standard. A relatively recent project to standardize annotations, led by Google and other big companies, including Sonar, is JSpecify. However, it’s been stale for the last year, and our analyzers do not yet support it.

I recommend checking with your company to see if there is an existing internal agreement and following it. Alternatively, using jakarta.annotation.Nullable (previously javax.annotation.Nullable) is a good option for the time being.

In the future, it would be great to adopt JSpecify annotations.