Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 this issue Mar 9, 2024 · 0 comments

Comments

@jlerbsc
Copy link

jlerbsc commented Mar 9, 2024

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;
                }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant