[英]Sonarqube not analyzing super class equals and potentially throwing a false positive for NPE
這是一個例子:
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
}
}
觀察到的問題的規則是:可能引發“ NullPointerException”。 “ obj”在此處為空。 我的問題是,處理此類情況的最佳方法是什么? 分析不是總能在super.equals(obj)
識別出空檢查嗎?
您的注釋表明這兩個類位於單獨的文件中。 因此,這個問題沒有得到解決。 SonarJava中沒有跨文件分析功能。
最好的方法是將其標記為“誤報”,然后繼續進行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.