diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/performance/InefficientStringBufferingRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/performance/InefficientStringBufferingRule.java index a2c298095a..3850e21101 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/performance/InefficientStringBufferingRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/performance/InefficientStringBufferingRule.java @@ -46,7 +46,7 @@ public class InefficientStringBufferingRule extends AbstractJavaRule { @Override public Object visit(ASTAdditiveExpression node, Object data) { - if (node.getParent() instanceof ASTConditionalExpression) { + if (node.getParent() instanceof ASTConditionalExpression || node.getNthParent(2) instanceof ASTConditionalExpression) { // ignore concats in ternary expressions return data; } diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/performance/xml/InefficientStringBuffering.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/performance/xml/InefficientStringBuffering.xml index 9533ad0279..0c31fbb10a 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/performance/xml/InefficientStringBuffering.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/performance/xml/InefficientStringBuffering.xml @@ -447,6 +447,7 @@ public class Foo { public String toString() { StringBuilder sb = new StringBuilder("Foo{"); sb.append("someInt=").append(this.someInt < 0 ? "n/a" : this.someInt + "ms"); + sb.append("someInt2=").append(this.someInt >= 0 ? this.someInt + "ms" : "n/a"); sb.append('}'); return sb.toString(); }