From 1f18181ef5a2a897dc543340a15b380dfd4cf49d Mon Sep 17 00:00:00 2001 From: Karl-Philipp Richter Date: Mon, 21 May 2018 06:10:07 +0200 Subject: [PATCH] Improve implementation hint in InefficientEmptyStringCheck The alternative implementation mentions iterating over the string and checking for whitespace which is pretty clear, however, showing the implementation doesn't hurt, nor does the hint for Apache commons-lang's StringUtils.isBlank which does exactly that. The if statement in the demonstration of inefficient code can lead to confusion because users _might_ think that the check is only inefficient inside an if statement although it's clear from the description that it's not. --- .../performance/InefficientEmptyStringCheckRule.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/performance/InefficientEmptyStringCheckRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/performance/InefficientEmptyStringCheckRule.java index f6c1023425..4f84d1f058 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/performance/InefficientEmptyStringCheckRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/performance/InefficientEmptyStringCheckRule.java @@ -13,7 +13,7 @@ import net.sourceforge.pmd.lang.java.symboltable.JavaNameOccurrence; * This rule finds code which inefficiently determines empty strings. This code * *
- *         if(str.trim().length()==0){....
+ * str.trim().length()==0
  * 
* *

@@ -22,8 +22,16 @@ import net.sourceforge.pmd.lang.java.symboltable.JavaNameOccurrence; *

* *
- * Character.isWhitespace(str.charAt(i));
+ * private boolean checkTrimEmpty(String str) {
+ *     for(int i=0; i
+ * or Apache commons-lang's StringUtils.isBlank.
  *
  * @author acaplan
  */