Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
353 views
in Technique[技术] by (71.8m points)

java - Deprecated annotations in FindBugs 2.0

Looking at the list of annotations in FindBugs 2.0, I see that a lot of them have been deprecated.

Some of these (@CheckForNull, @NonNull, etc.) have been deprecated because they have equivalent JSR-305 annotations. Good to finally settle the dilemma about which set of annotations to use.

But some FindBugs-specific annotations, such as @DefaultAnnotation and @DefaultAnnotationForFields, have also been deprecated and I cannot find any explanation of what to use in their place. I'm trying to migrate a codebase that makes heavy use of these annotations, and I'm a bit stuck.

I see that JSR-305 has @ParametersAreNonnullByDefault, which I could use to replace some instances of @DefaultAnnotationForParameters, but that will not cover all cases.

Am I missing something big here? Should I be using some kind of settings file or something, instead of annotations?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

(note: see a related article at Should annotations in jar305.jar be preferred over similar annotations in annotation.jar for FindBugs? )

From the author's PDF (here), on page 51:

JSR-305 will only define ParametersAreNonnullByDefault, but more can be defined outside of JSR-305

? and can be interpreted by static analyzers that interpret JSR-305 annotations

...so basically you can define it yourself, and give it the same name as the one you're replacing, and it should end up working fine since FindBugs only runs annotations by name (and likely prefers the JSR-305 annotations, maybe due to the deprecation in particular).

For an example, here is the source of @ParametersAreNonnullByDefault.

For more information, you might need to email the author of JSR-305 and FindBugs: Bill Pugh (here is his website). Also, the issue has been added to the Sourceforge bug tracker (here).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...