By Markus Sprunck; Revision: 1.3; Status: final; Last Content Change: Apr 25, 2013;
- NP_NONNULL_RETURN_VIOLATION - NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE - RV_RETURN_VALUE_IGNORED Basics about @Nonnull and @CheckReturnValue Annotations from JSR305For static code analysis tools it is sometimes difficult to correctly detect not null usage. With JSR305 the developer can help Findbugs in the analysis. I strongly recommend to check each possible NullPointerException, but sometimes it is a good idea not to suppress each unexpected behavior.
Nathaniel Ayewah and William Pugh [1] said: "Mistakes that manifest themselves by throwing exceptions are generally preferable to manifestations that silently and occasionally generate corrupted data or performance bottlenecks." Motivation for the 'Findbugs™ Warnings By Example' Series Unfortunately, some parts of the descriptions are not easy to understand (even for experienced Java developers). It can be difficult to understand the exact root cause for a warning and/or to find the correct way of fixing. To be honest - at least I had problems with some warnings in the last years. Quite often, I found no helping sample code in the web. The main weakness of the bug descriptions is, that it uses seldom sample code to demonstrate the wrong and correct situation. Example Code Findbugs™ (Version 2.0.1-rc2) will show all warnings with the minimum rank 13 (of concern) and confidence Low of the Findbugs™ Eclipse Plugin (Version 2.0.1.20120511). The code has been compiled with JDK 1.6.0_24. You will need the jsr305.jar (Findbugs lib directory) file in the class path.
The program should print the following to the standard output:
Findbugs Sample for NP_NONNULL_RETURN_VIOLATION - null - 12Findbugs Sample for NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE - null - nullFindbugs Sample for RV_RETURN_VALUE_IGNORED - nullReferences
|
