Software Engineering for Smart Data Analytics & Smart Data Analytics for Software Engineering
NP: Method call passes null for nonnull parameter (NP_NULL_PARAM_DEREF)
This method call passes a null value for a nonnull method parameter. Either the parameter is annotated as a parameter that should always be nonnull, or analysis has shown that it will always be dereferenced.
The structure described for method should match with the call of the method. Therefore, is necessary to use the same structure defined for the method such as in the annotations for the parameters. During the execution of the code is probably that variable passed to the method has not been initialized or the value assigned has taken a null value.
<code Java> public class FindBugs {
public static void main(String[] args) { String str = null; myMethod(str); } static String myMethod(@NonNull String myString){ System.out.print(myString); return myString; }
}
</Code>
<code Java> public class FindBugs {
public static void main(String[] args) {
String str = "myText"; if(str != null){ myMethod(str); }else{ throw new NullPointerException("NUll parametrer"); }
} static String myMethod(@NonNull String myString) { System.out.print(myString); return myString; }
}
</Code>
Benchmark project | Precision | Recall | ||||
---|---|---|---|---|---|---|
FB | JT | Delta | FB | JT | Delta | |
Apache Tomcat | 100% (1) | 0% | -100 | 100% | 100% | 0% |
Argo UML | 100% (2) | 0% | -100 | 100% | 100% | 0% |
AWT | 100% | 100% | 0 | 100% | 100% | 0% |
Jakarta | 100% (2) | 0% | -100 | 100% | 100% | 0% |
Java IO | 100% (2) | 0% | -100 | 100% | 100% | 0% |
JHotDraw | 100% (1) | 0% | -100 | 100% | 100% | 0% |
jrefactory | 100% (1) | 0% | -100 | 100% | 100% | 0% |
JServlet | 100% | 100% | 0 | 100% | 100% | 0% |
JUnit | 100% | 100% | 0 | 100% | 100% | 0% |
Lexi | 100% | 100% | 0 | 100% | 100% | 0% |
Mapper XML | 100% | 100% | 0 | 100% | 100% | 0% |
nutch | 100% | 100% | 0 | 100% | 100% | 0% |
PMD | 100% | 100% | 0 | 100% | 100% | 0% |
quickuml | 100% | 100% | 0 | 100% | 100% | 0% |
FB = FindBugs, JT = JTransformer, Delta = JTransformer - FindBug