Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Null Analysis With JSR-305 Annotations In Java 8
Null Analysis With JSR-305 Annotations In Java 8 [message #1262424] Mon, 03 March 2014 11:17 Go to next message
Brook Heisler is currently offline Brook Heisler
Messages: 1
Registered: March 2014
Junior Member
My team uses the JSR-305 nullness annotations instead of the Eclipse default ones. Prior to Java 8 this worked fine, but with the beta Java 8 support it doesn't (to name one example, inheriting a method with parameters of undefined nullness in a class with @ParametersAreNonNullByDefault and adding @Nullable still produces an Illegal Redefinition warning). I was going to file a bunch of bugs about this, but I tried it with the default annotations and found that it worked correctly (in my first test case, at least).

Is the null analysis expected to work with JSR-305 annotations or is this unsupported?
Re: Null Analysis With JSR-305 Annotations In Java 8 [message #1262598 is a reply to message #1262424] Mon, 03 March 2014 15:23 Go to previous message
Stephan Herrmann is currently offline Stephan Herrmann
Messages: 995
Registered: July 2009
Senior Member
Hi,

Let me start by reminding you that the name "JSR-305 annotations" is quite pretentious, since JSR 305 never produced any approved results. Unfortunately, the bad state of that JSR seems to hit back now, but I'm getting ahead of myself. Anyway, let's call'em FindBugs annotations for now.

Regarding null annotations, Java 8 is a game changer, because now we can regard nullness as an integral part of the type system, enabling much more complete analysis. The new kind of annotations is called "type annotations" and are brought to us by JSR 308.

Unfortunately, a few situations exist, were old style annotations and the new ones are not compatible, viz. annotations on arrays (and varargs) and annotations on qualified type names.

So, how can the compiler tell apart, which kind of annotations it is seeing? It has to look at the @Target specification of the annotation type. This should look like one of these:
- @Target({ FIELD, METHOD, PARAMETER, LOCAL_VARIABLE })
- @Target({ TYPE_USE })
If you see the first line, it's old style, if you see the second line, it's a type annotation.

I recently learned, that the FindBugs annotations lack any @Target specification. So, my first guess about the reason behind your problems would be: the compiler simply cannot decide how to treat these annotations which are neither old style nor new style annotations. This is a bug in those annotations.

Additionally, JDT may currently have a few problems with supporting old style annotations in Java 8 projects (old style in Java 7-, and new style in Java 8 should both be fine). Due to the current focus on Java 8, any bugs in that specific version mix will have to wait till after the March release.

If you installed a recent patch feature for Java 8 you should actually have both annotation libraries in your installation: org.eclipse.jdt.annotation 1.1.0 (old style) and 2.0.0 (type annotations). With these libraries it's up to you to chose the style. For any Java 8 projects I highly recommend to migrate to type annotations.

I hope this explains the situation a bit,
I still have to write a little migration guide, hope to get it done before the release ...

cheers,
Stephan
Previous Topic:jquery function call not working?
Next Topic:ASTParser: binding between statements
Goto Forum:
  


Current Time: Fri Aug 22 08:05:55 EDT 2014

Powered by FUDForum. Page generated in 0.01686 seconds