Abegail
Abegail

Reputation: 1

Java: Spotbugs-Annotation `@CheckForNull` deprecated. What to use instead?

In order to help my static code analysis, I have used the @CheckForNull -Annotation from spotbugs: edu.umd.cs.findbugs.annotations.CheckForNull

It has come to my awareness that this annotation though still working, is officially deprecated. What would you use in terms of best practice instead?

Best wishes Abegail

Searched google and forums, but cannot find an answer.

Upvotes: 0

Views: 359

Answers (2)

joseph
joseph

Reputation: 2816

findbugs Documentation says to use javax's CheckForNull instead.

You shouldn't use Nullable as it treats as if there is no annotation.

You want to keep using CheckForNull to enforce null checks in spotbugs.

Upvotes: 0

mernst
mernst

Reputation: 8127

Answered here: What @Nullable to use in Java (as of 2023/JDK21)?

In brief:

The best choice for the @Nullable and @NonNull annotation remains that of the Checker Framework. It is the de facto standard (import org.checkerframework.checker.nullness.qual... appears in 95k files on GitHub), is recognized by the widest variety of tools, is a superset of most other nullness annotations, and has a clear, standard semantics.

Upvotes: 0

Related Questions