@Null / @NotNull

Heiko W.Rupp hrupp at redhat.com
Thu Nov 28 16:12:30 UTC 2013


Am 28.11.2013 um 16:57 schrieb John Mazzitelli <mazz at redhat.com>:
> They are useless because, as Heiko mentioned, our code doesn't match the annotations. I assume this means Heiko say an instance where we had something like @Null but the code actually didn't check for null and caused an NPE. In that sense I use the term "useless" 

Exactly. And this is where I say such an annotation or/and Javadoc thelling me that I must not pass null / may pass null
and the implementation does something else is confusing up to dangerous.

http://stackoverflow.com/questions/4963300/which-notnull-java-annotation-should-i-use

Has a longish discussion (but a bit old). 

It looks like there is support for Jetbrains ones / JSR305 ones in various places including
Findbugs, an ant task, some Eclipse releases (Juno) and IJ, so the Jetbrains ones are not 
limited to IJ users.

BeanValidation is a different beast and we may use that or just the annotations from it, but
the "beauty" of @Null / @NotNull is that tools like IDEs and Findbugs can make static code
analysis and directly warn you when you try to pass null to a method that has a @NotNull parameter.

  Heiko





More information about the rhq-devel mailing list