[java] InefficientStringBuffering: fix another ternary false positive

This commit is contained in:
Andreas Dangel
2020-06-18 12:10:36 +02:00
parent 2ed80df735
commit f1d46714a5
2 changed files with 2 additions and 1 deletions

View File

@ -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;
}

View File

@ -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();
}