

直到我修改为这样的代码才通过——
public class DetectorImport {
public String check1(Nonentity nonentity) {
String s;
if(nonentity == null) {
s = null;
}else {
s = nonentity.getName();
}
if(s !=null) {
s = s.replaceAll("(", "(");
}
return s;
}
}
查到的几个相关问题——
https://community.sonarsource.com/tags/c/bug/fp/7/java
Sonarqube is raising false-positive NPE
2019-07-19
I expect that nonNull implementation is in the another file than the main code. Unfortunately that’s the current limitation we have for this rule. If you move nonNull in the file, FP should disappear.
This problem can’t be fixed easily, so for now I suggest you to mark issue as FP in SonarQube UI.
Anyway thanks for reporting it.
[JAVA] squid:S2259 False Positive with Utility methods
这里提到是支持apache commen的StringUtils包的。
We currently support methods from commons-lang StringUtils (v2, and v3), guava preconditions, and java 8 methods from java.util.Objects (nonNull, isNull, requireNonNull). As we know how these methods behave, we are able to correctly handle such call and discard similar FPs. Of course, I don't want to force you using such libraries to make the analyzer happy. :)
report this on Sonar Community: Commons-lang StringUtils isNotBlank method still raise NPE