diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/StringConcatToTextBlockFixCore.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/StringConcatToTextBlockFixCore.java index 54ec1384b1e..b62b0651445 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/StringConcatToTextBlockFixCore.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/StringConcatToTextBlockFixCore.java @@ -752,6 +752,9 @@ public boolean visit(SimpleName simpleName) { if (!checkValidityVisitor.isValid()) { return failure(); } else if (checkValidityVisitor.isPassedAsArgument()) { + if (fLiterals.size() < 3) { + return failure(); + } List statements= new ArrayList<>(statementList); List literals= new ArrayList<>(fLiterals); ModifyStringBufferToUseTextBlock operation= new ModifyStringBufferToUseTextBlock(node, statements, diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AssistQuickFixTest15.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AssistQuickFixTest15.java index 3c132d97e56..dfd474c2975 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AssistQuickFixTest15.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AssistQuickFixTest15.java @@ -816,6 +816,13 @@ public void foo() { // comment 1 int index = buf3.indexOf("null"); bufFunc(buf3); + StringBuilder buf13 = new StringBuilder(); + bufFunc(buf13); + StringBuilder buf14 = new StringBuilder("abcd\\n"); + bufFunc(buf14); + StringBuilder buf15 = new StringBuilder("abcd\\n"); + buf15.append("efg"); + bufFunc(buf15); \s } public void bufFunc(StringBuilder x) { @@ -842,6 +849,13 @@ public void foo() { // comment 1 int index = buf3.indexOf("null"); bufFunc(buf3); + StringBuilder buf13 = new StringBuilder(); + bufFunc(buf13); + StringBuilder buf14 = new StringBuilder("abcd\\n"); + bufFunc(buf14); + StringBuilder buf15 = new StringBuilder("abcd\\n"); + buf15.append("efg"); + bufFunc(buf15); \s } public void bufFunc(StringBuilder x) { diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/CleanUpTest15.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/CleanUpTest15.java index 6a9d3e1d385..e80f8866d5f 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/CleanUpTest15.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/CleanUpTest15.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2021, 2024 Red Hat Inc. and others. + * Copyright (c) 2021, 2025 Red Hat Inc. and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -415,6 +415,13 @@ public void foo() { buf12.append("ijkl\\n"); buf12.append("mnopq\\n"); bufFunc(buf12); + StringBuffer buf13 = new StringBuffer(); + bufFunc(buf13); + StringBuffer buf14 = new StringBuffer("abcd\\n"); + bufFunc(buf14); + StringBuffer buf15 = new StringBuffer("abcd\\n"); + buf15.append("efg"); + bufFunc(buf15); } private void write(CharSequence c) { System.out.println(c); @@ -554,6 +561,13 @@ public class C { mnopq \"""); bufFunc(buf12); + StringBuffer buf13 = new StringBuffer(); + bufFunc(buf13); + StringBuffer buf14 = new StringBuffer("abcd\\n"); + bufFunc(buf14); + StringBuffer buf15 = new StringBuffer("abcd\\n"); + buf15.append("efg"); + bufFunc(buf15); } private void write(CharSequence c) { System.out.println(c);