You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by Kristian Rosenvold <kr...@gmail.com> on 2013/05/17 23:32:55 UTC

Proposal: @Nullable and @Nonnull in maven

I had a little chat with the guys at the findbugs mailing list which has
made this all a lot easier, even to thickheads like me:

It turns out we do not have to "subscribe" to anything like JSR-305 at all.
I probably watched the movie "Highlander" too much in my teens, which had
me searching too much for the "there can be only one" kind of solution.

Since I love source code, I'll just point you all at the findbugs source I
was given:

http://code.google.com/p/findbugs/source/browse/trunk/findbugs/src/java/edu/umd/cs/findbugs/ba/NullnessAnnotation.java#55

This shows the part where findbugs searches for /any/ kind of @Nonnull
annotation and also @Nullable. The guys at findbugs realized that there
does not have to be only one. And it turns out the IntelliJ guys also
understood this, so we can add any arbitrary annotation to the
"nullability" section of the idea code-style file. (As for eclipse, well -
ahem - I'm sure the eclipse users out there will solve this. It' s OSS  :)

So the proposal is really simple:

We make "maven-annotations" under maven-shared. RC for this can be found at
https://github.com/krosenvold/maven-annotations.git

this implementation does /not/ depend on any specific "jsr" or any other
dependency, so we can freely leak this from maven core into plugins.

 We specifically leak

org.apache.maven.shared.annotations.Nonnull
org.apache.maven.shared.annotations.Nullable

from maven core into plugins. From the moment we publish these, they cannot
ever change.

If core exposes version "1.0" of "maven-annotations" and a plugin includes
version "1.1" of maven-annotations, the *additional* definitions in 1.1
will be loaded from the 1.1 jar, while Nonnull and Nullable will leak in
their 1.0 versions from core.

Kristian

Re: Proposal: @Nullable and @Nonnull in maven

Posted by Hervé BOUTEMY <he...@free.fr>.
this seems reasonable to me, starting basic with the most important case and 
able to extend in the future

I just checked how it is done in Eclipse: Eclipse has its own annotations [1], 
and null check seems to be configurable [2], but only with one null annotation 
at a time.

Now back to proposed annotations.
While looking at Eclipse annotations, I noticed that:
- same annotation attributes: none :)
- different retention strategy
- restricted target
I didn't look at JSR 305 equivalent annotations, nor Findbugs ones, but I 
suppose there is a right definition to choose.

Regards,

Hervé

[1] 
http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/tree/org.eclipse.jdt.annotation/src/org/eclipse/jdt/annotation

[2] http://wiki.eclipse.org/JDT_Core/Null_Analysis#Usage

Le vendredi 17 mai 2013 23:32:55 Kristian Rosenvold a écrit :
> I had a little chat with the guys at the findbugs mailing list which has
> made this all a lot easier, even to thickheads like me:
> 
> It turns out we do not have to "subscribe" to anything like JSR-305 at all.
> I probably watched the movie "Highlander" too much in my teens, which had
> me searching too much for the "there can be only one" kind of solution.
> 
> Since I love source code, I'll just point you all at the findbugs source I
> was given:
> 
> http://code.google.com/p/findbugs/source/browse/trunk/findbugs/src/java/edu/
> umd/cs/findbugs/ba/NullnessAnnotation.java#55
> 
> This shows the part where findbugs searches for /any/ kind of @Nonnull
> annotation and also @Nullable. The guys at findbugs realized that there
> does not have to be only one. And it turns out the IntelliJ guys also
> understood this, so we can add any arbitrary annotation to the
> "nullability" section of the idea code-style file. (As for eclipse, well -
> ahem - I'm sure the eclipse users out there will solve this. It' s OSS  :)
> 
> So the proposal is really simple:
> 
> We make "maven-annotations" under maven-shared. RC for this can be found at
> https://github.com/krosenvold/maven-annotations.git
> 
> this implementation does /not/ depend on any specific "jsr" or any other
> dependency, so we can freely leak this from maven core into plugins.
> 
>  We specifically leak
> 
> org.apache.maven.shared.annotations.Nonnull
> org.apache.maven.shared.annotations.Nullable
> 
> from maven core into plugins. From the moment we publish these, they cannot
> ever change.
> 
> If core exposes version "1.0" of "maven-annotations" and a plugin includes
> version "1.1" of maven-annotations, the *additional* definitions in 1.1
> will be loaded from the 1.1 jar, while Nonnull and Nullable will leak in
> their 1.0 versions from core.
> 
> Kristian

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org