[英]Sonarqube not analyzing super class equals and potentially throwing a false positive for NPE
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; 观察到的问题的规则是:可能引发“ NullPointerException”。 "obj" is nullable here.
“ obj”在此处为空。 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)
? 分析不是总能在
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.
SonarJava中没有跨文件分析功能。
Your best course is to mark this a False Positive and move on. 最好的方法是将其标记为“误报”,然后继续进行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.