Why is this an issue?

Operations performed on a string with predictable outcomes should be avoided. For example:

How to fix it

Avoid performing the operation that has a predictable outcome.

Code examples

Noncompliant code example

String speech = "SonarQube is the best static code analysis tool."

String s1 = speech.substring(0); // Noncompliant - yields the whole string
String s2 = speech.substring(speech.length()); // Noncompliant - yields "";
String s3 = speech.substring(5, speech.length()); // Noncompliant - use the 1-arg version instead

if (speech.contains(speech)) { // Noncompliant - always true
    // ...
}

Compliant solution

String speech = "SonarQube is the best static code analysis tool."

String s1 = speech;
String s2 = "";
String s3 = speech.substring(5);

// ...

Resources