Does Sonar support commons-lang StringUtils ?
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.7</version>
</dependency>
Env:
INFO: SonarQube Scanner 3.2.0.1227
INFO: Java 1.8.0_121 Oracle Corporation (64-bit)
INFO: Linux 4.19.2-1.el7.elrepo.x86_64 amd64
Community EditionVersion 7.6 (build 21501)
code to reproduce this issue:
public class DetectorImport {
public String check1(Nonentity nonentity) {
String s;
if(nonentity == null) {
s = null;
}else {
s = nonentity.getName();
}
if(StringUtils.isNotBlank(s)) {
s = s.replaceAll("(", "(");
}
return s;
}
}
[JAVA] squid:S2259 False Positive with Utility methods
from this thread, I get the following info:
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.
According to this thread Sonarqube is raising false-positive NPE, NullPointer issue should be checked in the same file.
changing above code to following one indeed solve this issue:
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;
}
}
It seems that commons-lang StringUtils isn’t supported yet