diff --git a/pmd-java/src/main/resources/rulesets/java/strings.xml b/pmd-java/src/main/resources/rulesets/java/strings.xml index dc3f70cd76..c09cbbbed2 100644 --- a/pmd-java/src/main/resources/rulesets/java/strings.xml +++ b/pmd-java/src/main/resources/rulesets/java/strings.xml @@ -221,7 +221,10 @@ if (s.indexOf('d') {} String.trim().length() is an inefficient way to check if a String is really empty, as it creates a new String object just to check its size. Consider creating a static function that loops through a string, checking Character.isWhitespace() on each character and returning -false if a non-whitespace character is found. +false if a non-whitespace character is found. Note that Apache's commons-lang library includes +the isBlank function, which does exactly that. You can also copy the source code of the function +(https://commons.apache.org/proper/commons-lang/apidocs/src-html/org/apache/commons/lang3/StringUtils.html#line.296) +if you'd rather not add the library to your classpath. 3