DaveAKing / guava-libraries

Automatically exported from code.google.com/p/guava-libraries
Apache License 2.0
0 stars 0 forks source link

Preconditons.checkNotNull should be marked as (returning) @Nonnull #1396

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The Preconditons.checkNotNull methods all return the argument, so if the method 
itself can be marked as @Nonnull, then someone can write something like

public void foo(Object bar) {
    bar = checkNotNull(bar);
    bar.x();
}

and null analysis will know "bar" cannot be null on the second line without 
having to analyse checkNotNull. This trick seems to work quite well with 
Eclipse Juno's null analysis.

Original issue reported on code.google.com by billc...@gmail.com on 2 May 2013 at 1:48

GoogleCodeExporter commented 9 years ago
We haven't yet used @Nonnull anywhere in Guava, FWIW.

Original comment by lowas...@google.com on 3 May 2013 at 9:09

GoogleCodeExporter commented 9 years ago
Right. I failed to notice the @ParametersAreNonnullByDefault annotation in 
package-info.java.

Sorry about the trouble.

Original comment by billc...@gmail.com on 4 May 2013 at 9:26

GoogleCodeExporter commented 9 years ago

Original comment by kurt.kluever on 4 May 2013 at 10:28

GoogleCodeExporter commented 9 years ago
> I failed to notice the @ParametersAreNonnullByDefault annotation in 
package-info.java.

Though to be fair, that does only say that _parameters_ are non-null by 
default, not return types. There's another issue related to this topic, so I'm 
going to mark this as a dup of that one.

Original comment by cgdec...@gmail.com on 4 May 2013 at 5:13

GoogleCodeExporter commented 9 years ago
This issue has been migrated to GitHub.

It can be found at https://github.com/google/guava/issues/<issue id>

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:12

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 3 Nov 2014 at 9:08