I use “HP Fortify v3.50” in a java project, and I find many false positives on “Null Dereference” because Fortify does not see the control against null in another method. How can I reduce false positives and maintain the rule?
Here is the POC
public class MyClass { public static void main(String[] args) { String string01 = null; String string02 = null; int i; if (args[0].equals("A")) { string01 = "X"; string02 = "Y"; } if (!isNull(string02)){ i = string02.length();}
Result:
[E8837DB548E01DB5794FA71F3D5F51C8 : medium : Null Dereference : controlflow ] MyClass.java(13) : Assigned null : string02 MyClass.java(16) : Branch not taken: (!args[0].equals("A")) MyClass.java(20) : Branch taken: (!isNull(string02)) //False Positive MyClass.java(21) : Dereferenced : string02 [E8837DB548E01DB5794FA71F3D5F51C9 : medium : Null Dereference : controlflow ] MyClass.java(13) : Assigned null : string02 MyClass.java(16) : Branch not taken: (!args[0].equals("A")) MyClass.java(20) : Branch not taken: isNull(string02) MyClass.java(23) : Dereferenced : string02
source share