soapui icon indicating copy to clipboard operation
soapui copied to clipboard

Quality: RSPEC-2692 "indexOf" checks must not be used to check whether a value is included in a string or a list

Open jlerbsc opened this issue 11 months ago • 0 comments

Using our java code remediation solution, we detected that the project's source code contained 3 violations of the Sonar rule RSPEC-2692 "indexOf" checks must not be used to check whether a value is included in a string or a list". Below is an example of how our Indepth solution could fix the problem (https://www.indepth.fr/) For your information, using Indepth is free for all Opensource projects.

    com\eviware\soapui\impl\wsdl\support\PathUtils.java
    @@ -159,5  +159,5 @@
        }



-        if (StringUtils.isNullOrEmpty(project.getPath()) && project.getResourceRoot().indexOf("${projectDir}") >= 0) {
+        if (StringUtils.isNullOrEmpty(project.getPath()) && project.getResourceRoot().contains("${projectDir}")) {
            if (UISupport.confirm("Save project before setting path?", "Project has not been saved")) {
                try {

    com\eviware\soapui\model\propertyexpansion\PropertyExpansionUtils.java
    @@ -461,5  +461,5 @@

    public static boolean containsPropertyExpansion(String str) {
-        return str != null && str.indexOf("${") >= 0 && str.indexOf('}') > 2;
+        return str != null && str.contains("${") && str.indexOf('}') > 2;
    }
}

    com\eviware\soapui\support\SecurityScanUtil.java
    @@ -101,5  +101,5 @@
                }
            } else {
-                if (content.toUpperCase().indexOf(replToken.toUpperCase()) >= 0) {
+                if (content.toUpperCase().contains(replToken.toUpperCase())) {
                    result = replToken;
                }

jlerbsc avatar Mar 09 '24 20:03 jlerbsc