xavierm02 xavierm02 - 2 years ago 118
Java Question

edu.umd.cs.findbugs.annotations deprecated? What should I use for null annotations?

I'm new to Java and just discovered the @Nullable and other such annotations, so I tried them.

I first tried the ones included in Eclipse, but they didn't allow me to use them for fields, and that made me think some fields could be null whereas they clearly couldn't.

By the way, I was using the thing to make everything @NonNull by default.

Then, I tried findbugs (edu.umd.cs.findbugs.annotations), but apparently, the whole thing is deprecated ( http://findbugs.sourceforge.net/api/edu/umd/cs/findbugs/annotations/package-summary.html ).

What am I supposed to use?

Answer Source

When something is marked as @Deprecated, an alternative will usually be provided in the Javadoc for the deprecated declaration.

In this case, the HTML-formatted Javadoc is failing you: it's not showing the fully-qualified class name of the alternative, so you see something like

Nullable: Deprecated. -Use Nullable instead

Which isn't very helpful.

So let's look at the source for Nullable.java instead:

 * The annotated element could be null under some circumstances.
 * ...
 * @deprecated - use {@link javax.annotation.Nullable} instead. 

Aha: It's javax.annotation.Nullable we're supposed to use instead. But this is a bigger question. I suggest you look here: Which @NotNull Java annotation should I use?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download