Here is an example:
public class A{
public boolean equals(Object a){
if(a == null)
return false;
// Some Implementation
}
}
public class B extends A {
public boolean equals(Object obj){
if(this == obj)
return true;
if(!super.equals(obj)) // null check for obj is already there in super.equals
return false;
if(getClass() != obj.getClass())
return false;
// Some Implementation
}
}
The rule for the issue observed is A "NullPointerException" could be thrown; "obj" is nullable here. My question is, what's the best way to handle such scenarios? Wouldn't the analysis not be able to always to identify the null check in super.equals(obj)
?
Your comments indicate that the two classes are in separate files. That's why the issue is not suppressed; cross-file analysis just isn't available in SonarJava.
Your best course is to mark this a False Positive and move on.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.