diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java index de49705d7a6..daa87cf9750 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java @@ -7813,4 +7813,23 @@ public void testIssue2127b() { """, CodeFormatter.K_MODULE_INFO | CodeFormatter.F_INCLUDE_COMMENTS); } +/** + * https://github.com/eclipse-jdt/eclipse.jdt.core/issues/3372 + */ +public void testIssue3372() { + String source = + """ + /** + *
+		 * {@code
+		 * void test() {
+		 *   int i;
+		 * }
+		 * 
+ */ + class Test { + } + """; + formatSource(source); +} } diff --git a/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/CommentsPreparator.java b/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/CommentsPreparator.java index 10aa3e1bbe5..9e3154e2dde 100644 --- a/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/CommentsPreparator.java +++ b/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/CommentsPreparator.java @@ -1017,7 +1017,8 @@ private void handleFormatCodeTag(TagElement tagElement, int startPos, int endPos // int closingBracePos = src.lastIndexOf('}', tag.getStartPosition() + tag.getLength()); // TODO bug 570137 workaround int closingBracePos = tag.getStartPosition() + 1; - for (int braces = 1; braces > 0 && closingBracePos < src.length(); closingBracePos++) { + int lastPos = this.ctm.get(this.ctm.size() - 2).originalEnd; + for (int braces = 1; braces > 0 && closingBracePos < lastPos; closingBracePos++) { if (src.charAt(closingBracePos) == '{') braces++; if (src.charAt(closingBracePos) == '}')