From 93bb96d40cd52801399e8ed23a09feb822f49e35 Mon Sep 17 00:00:00 2001 From: Liam Miller-Cushon Date: Thu, 29 Oct 2026 06:04:15 -0700 Subject: [PATCH] Add tests demonstrating unclosed Javadoc inline tags leaving comments unformatted. In classic Javadoc comments, an unclosed inline tag outside `
`
(for example, an unclosed `{@link ...` lacking a closing `}`) causes lexing
to fail with a `LexException` in `checkMatchingTags()`. Because
`JavadocFormatter` catches `LexException` and returns the input string
unmodified, the comment is left completely unformatted.

Add tests reproducing this behavior with unclosed inline tags before
subsequent list items, blank lines, footer tags, and at the end of the comment.

PiperOrigin-RevId: 1009630980
---
 .../java/JavadocFormattingTest.java           | 94 +++++++++++++++++++
 1 file changed, 94 insertions(+)

diff --git a/core/src/test/java/com/google/googlejavaformat/java/JavadocFormattingTest.java b/core/src/test/java/com/google/googlejavaformat/java/JavadocFormattingTest.java
index f0014a211..92f65be6b 100644
--- a/core/src/test/java/com/google/googlejavaformat/java/JavadocFormattingTest.java
+++ b/core/src/test/java/com/google/googlejavaformat/java/JavadocFormattingTest.java
@@ -2622,6 +2622,100 @@ class Test {}
     doFormatTest(input, expected);
   }
 
+  @Test
+  public void unclosedInlineTagInList() {
+    String input =
+        """
+        /**
+         * 
+         */
+        class Test {}
+        """;
+    // TODO(b/407787200): Lexing fails due to unclosed inline tag, leaving comment unformatted.
+    String expected =
+        """
+        /**
+         * 
+         */
+        class Test {}
+        """;
+    doFormatTest(input, expected);
+  }
+
+  @Test
+  public void unclosedInlineTagAtEndOfComment() {
+    String input =
+        """
+        /**
+         * Return the child position of this cell within its parent. For more details, see {@link com.google.common.geometry.S2CellId
+         */
+        class Test {}
+        """;
+    // TODO(b/407787200): Lexing fails due to unclosed inline tag, leaving comment unformatted.
+    String expected =
+        """
+        /**
+         * Return the child position of this cell within its parent. For more details, see {@link com.google.common.geometry.S2CellId
+         */
+        class Test {}
+        """;
+    doFormatTest(input, expected);
+  }
+
+  @Test
+  public void unclosedInlineTagBeforeBlankLine() {
+    String input =
+        """
+        /**
+         * Some description with {@link #validating() sets (allowInvalid=false, mayDissolve=false, snapFunction=null): Do not modify the input geometry.
+         *
+         * 

Next paragraph that is also long enough to exceed the line length limit and require line wrapping. + */ + class Test {} + """; + // TODO(b/407787200): Lexing fails due to unclosed inline tag, leaving comment unformatted. + String expected = + """ + /** + * Some description with {@link #validating() sets (allowInvalid=false, mayDissolve=false, snapFunction=null): Do not modify the input geometry. + * + *

Next paragraph that is also long enough to exceed the line length limit and require line wrapping. + */ + class Test {} + """; + doFormatTest(input, expected); + } + + @Test + public void unclosedInlineTagBeforeFooterTag() { + String input = + """ + /** + * Some description with {@link #validating() sets (allowInvalid=false, mayDissolve=false, snapFunction=null): Do not modify the input geometry. + * + * @param x a parameter description that is also long enough to exceed the line length limit and require line wrapping + */ + class Test {} + """; + // TODO(b/407787200): Lexing fails due to unclosed inline tag, leaving comment unformatted. + String expected = + """ + /** + * Some description with {@link #validating() sets (allowInvalid=false, mayDissolve=false, snapFunction=null): Do not modify the input geometry. + * + * @param x a parameter description that is also long enough to exceed the line length limit and require line wrapping + */ + class Test {} + """; + doFormatTest(input, expected); + } + // TODO: b/346668798 - Test the following Markdown constructs, and make the tests work as needed. // We can assume that the CommonMark parser correctly handles Markdown, so the question is whether // they are subsequently mishandled by our formatting logic. So for example the CommonMark parser