So vermeiden Sie falsch positives "Null -Derreference" -Fehler in der BefestigungJava

Java-Forum
Anonymous
 So vermeiden Sie falsch positives "Null -Derreference" -Fehler in der Befestigung

Post by Anonymous »

Ich verwende "HP Fectify v3.50" für ein Java -Projekt und finde viele falsch positive positive "null Dereference", da die Verstärkung nicht sieht, dass die Kontrolle gegen Null in einer anderen Methode ist.

Code: Select all

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();} //False Positive
else {
i = string02.length();
} // Yes, it is an error!
}

public static boolean isNull(Object toBeTested){
return (null == toBeTested);
}
}
< /code>

< /p>

Ergebnis: < /p>

[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

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post