Operations performed on a string with predictable outcomes should be avoided. For example:
Avoid performing the operation that has a predictable outcome.
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 // ... }
String speech = "SonarQube is the best static code analysis tool." String s1 = speech; String s2 = ""; String s3 = speech.substring(5); // ...