Having compiled the original example in Eclipse in accordance with 1.8 and including annotation-based null analysis, we get this warning:
directPathToA(y); ^ Null type safety (type annotations): The expression of type 'Integer' needs unchecked conversion to conform to '@NonNull Integer'
This warning is similar to the warnings you receive when mixing generated code with legacy code using raw types (“unchecked conversion”). Here we have the same situation: the indirectPathToA() method has an "obsolete" signature, in which it does not indicate a single null contract. Tools can easily report this, so they will chase you along all the alleys where you need to exchange null annotations, but not yet.
And when using smart @NonNullByDefault we don’t even have to talk about it every time.
In other words: whether or not null annotations can “spread very far” depends on the tool you use and on how closely you follow all warnings issued by the tool. With TYPE_USE null annotations , you finally have the option of letting the tool warn you about every possible NPE in your program, because nullness becomes an integral property of the type system.
Stephan Herrmann Sep 18 '15 at 22:06 2015-09-18 22:06
source share