Repository navigation
Description
Upstream: google/google-java-format#1545
Kind: feature | Priority: medium
Google's formatter parses /// Markdown doc comments (JEP 467) with CommonMark and reformats them. It was introduced in October and has been polished since. On 2026-11-26 three fixes landed: google-java-format#1543 never wraps a line so that a block marker (list, quote, heading, fence, table separator, HTML block) starts the continuation line; google-java-format#1544 stops tokens that contain raw newlines from emitting lines without the /// prefix (this could corrupt code); google-java-format#1545 keeps HTML list tags (<ul>, <li>) from adding indentation, because 4+ columns would turn the following paragraphs into indented code blocks.
Why it matters to us: we only handle /// at the comment-token level. Our JavaCommentsHelper wraps long lines and keeps the /// prefix (our #102, port of palantir 1776), and nothing else in open-java-format/src/main mentions Markdown or CommonMark. A wrap can therefore put -, >, # or 1. at the start of a continuation line and silently change the rendered docs. The three upstream commits also document the bug classes a Markdown-aware wrapper must avoid, so they are good test cases even if we never adopt the CommonMark pipeline. I did not run our formatter; the "Before" is derived from reading JavaCommentsHelper.
Before (how it is formatted today: short lines are left as written, only over-long lines are wrapped):
class T {
/// Intro <ul><li>a</ul> trailing words.
void m() {}
}After (google-java-format with the change, expected output of its test):
class T {
/// Intro
/// <ul>
/// <li>a
/// </ul>
/// trailing words.
void m() {}
}Affected files in our repo:
- open-java-format/src/main/java/com/palantir/javaformat/java/JavaCommentsHelper.java (wrapping of
///runs, around the Markdown comments) - open-java-format/src/main/java/com/palantir/javaformat/java/javadoc/JavadocLexer.java, JavadocWriter.java, JavadocFormatter.java (classic Javadoc only today)
- open-java-format/src/test/java/com/palantir/javaformat/java/JavaCommentsHelperTest.java
Suggested action: investigate. Step 1 (cheap): in the /// wrapper, never break before a CommonMark block marker, and add the cases from the upstream tests (google-java-format#1543). Step 2 (decision): consciously adopt or reject full Markdown-aware formatting; it needs the CommonMark dependency and upstream's lexer/writer changes, which do not map one to one onto our Javadoc code. Upstream is still changing this area almost daily, so watch it for a few more runs before committing to a port.
Filed from an upstream-watch ticket after manual review.
Activity