FindBugs assumes that it has all code available during execution. This assumption can be dangerous, As shown in the following example.
The class GoodBehavingClass will always return a non null String object in the method isNullReturned which according to FindBugs should not be checked against null in the checkIfNullIsReturned method. When this class is part of a library which is distributed to third parties it can lead to extension of the GoodBehavingClass by BadBehavingClass which always returns null, which would lead to NullPointerExceptions when passed to this checkIfNullIsReturned method when this redundant null check is removed.
I think you can only state this redundant null check only when the method or class is declared as final.
Log in to post a comment.