diff --git a/open-java-format/src/main/java/com/palantir/javaformat/java/javadoc/JavadocLexer.java b/open-java-format/src/main/java/com/palantir/javaformat/java/javadoc/JavadocLexer.java index 78116960a..a4e61b40f 100644 --- a/open-java-format/src/main/java/com/palantir/javaformat/java/javadoc/JavadocLexer.java +++ b/open-java-format/src/main/java/com/palantir/javaformat/java/javadoc/JavadocLexer.java @@ -92,7 +92,11 @@ private static String stripJavadocBeginAndEnd(String input) { */ checkArgument(input.startsWith("/**"), "Missing /**: %s", input); checkArgument(input.endsWith("*/") && input.length() > 4, "Missing */: %s", input); - return input.substring("/**".length(), input.length() - "*/".length()); + int end = input.length() - "*/".length(); + while (end > "/**".length() && input.charAt(end - 1) == '*') { + end--; + } + return input.substring("/**".length(), end); } private final CharStream input; diff --git a/open-java-format/src/test/java/com/palantir/javaformat/java/JavadocFormattingTest.java b/open-java-format/src/test/java/com/palantir/javaformat/java/JavadocFormattingTest.java index da51929fe..bdc14d98f 100644 --- a/open-java-format/src/test/java/com/palantir/javaformat/java/JavadocFormattingTest.java +++ b/open-java-format/src/test/java/com/palantir/javaformat/java/JavadocFormattingTest.java @@ -570,6 +570,35 @@ void significantAsterisks() { doFormatTest(input, expected); } + @Test + void trailingAsterisksBeforeClose() { + String[] input = { + "/** Version information for all the QuotaKeys that we have data for **/", // + "class Test {}", + }; + String[] expected = { + "/** Version information for all the QuotaKeys that we have data for */", // + "class Test {}", + }; + doFormatTest(input, expected); + } + + @Test + void trailingAsterisksOnTheirOwnLine() { + String[] input = { + "/**", // + " * Summary line", + " * continues here.", + " ***/", + "class Test {}", + }; + String[] expected = { + "/** Summary line continues here. */", // + "class Test {}", + }; + doFormatTest(input, expected); + } + @Test void links() { String[] input = {