While running SpotBugs on our code, the tool noted:
Possible null pointer dereference
There is a branch of statement that, if executed, guarantees that a null value will be dereferenced, which would generate a NullPointerException when the code is executed. Of course, the problem might be that the branch or statement is infeasible and that the null pointer exception cannot ever be executed; deciding that is beyond the ability of SpotBugs.
Bug kind and pattern: NP - NP_NULL_ON_SOME_PATH
Apologies for the screenshot, the tool doesn't allow selecting the text:
The problem appears to be with the following lines:
public boolean matchesParameters(List<Class<?>> _wantedArgs) {
if (parameterTypes != null && _wantedArgs == null) {
return false;
}
if (parameterTypes.size() != _wantedArgs.size()) {
return false;
}
The parameterTypes != null is a null guard that can be skipped, resulting in an NPE when _wantedArgs isn't null (due to dereferencing the size at parameterTypes.size()). It may be safer to write this as follows:
While running SpotBugs on our code, the tool noted:
Apologies for the screenshot, the tool doesn't allow selecting the text:
The problem appears to be with the following lines:
The
parameterTypes != null
is anull
guard that can be skipped, resulting in an NPE when_wantedArgs
isn'tnull
(due to dereferencing the size atparameterTypes.size()
). It may be safer to write this as follows: