SmartBear / soapui

SoapUI is a free and open source cross-platform functional testing solution for APIs and web services.
http://www.soapui.org
Other
1.58k stars 611 forks source link

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

Open jlerbsc opened 8 months ago

jlerbsc commented 8 months ago

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;
                }