Repository navigation
Keep the blank line before a Javadoc <div> instead of inferring a <p> - #270
Merged
abashev merged 1 commit intoNov 24, 2026
Merged
Conversation
Where a blank line separates two words of a Javadoc comment, the lexer infers a <p> in front of the second. When that word is a <div> start tag, the <p> comes out empty: a <p> cannot hold a <div>, so the <div> closes it, and doclint warns "empty <p> tag". The blank line now stays without the <p>, as google-java-format#1534 proposes. <DIV> and <div class=...> count, <div-custom> does not, and a <p> written in the comment stays. Inside a list item or a block tag the writer turns the blank lines that other tokens ask for into newlines. A newline before the <div> would be plain whitespace the next time the output is formatted, and the <div> would join the line before it, so this blank line is written there too. The upstream change writes a newline, and so changes its own output on a second pass. Among the 128k files of JDK 21's src.zip and the Gradle cache's sources jars, 17 have a Javadoc line that starts with a <div>. In 7 of them an inferred <p> goes, and nothing else changes; formatting the output again changes nothing. Fixes #268.
abashev
deleted the
abashev/javadoc-do-not-insert-a-p-tag-before-a-div-that
branch
November 24, 2026 11:33
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #268. Based on
21.X.X; there are no other open pull requests.Where a blank line separates two words of a Javadoc comment,
JavadocLexer.inferParagraphTagsputs a<p>in front of the second. When that word is a<div>start tag, the<p>comes out empty: a<p>cannot hold a<div>, so the<div>closes it, and doclint warnsempty <p> tag. google-java-format#1534 (open, its author has not signed the CLA) keeps the blank line there instead; this does the same in our lexer.was formatted with
<p><div class="notice">and now stays as it is.What changes
inferParagraphTagsturns the whitespace into a newBLANK_LINEtoken, instead of adding a<p>after it, when the next literal starts a<div>:<div>,<DIV>,<div/>, or<divalone, which is how a tag with attributes starts, since a literal ends at whitespace.<div-custom>,<span>and plain text still get a<p>, and a<p>written in the comment stays.Lists and block tags. Inside a list item or a block tag such as
@param, the writer turns the blank lines that other tokens ask for into newlines. A newline before the<div>would be plain whitespace the next time the output is formatted, and the<div>would join the line before it. SoBLANK_LINEasks the writer for aFORCED_BLANK_LINE, which is written there too:The upstream change writes a newline there, and so changes its own output on a second pass; its test has no list or block tag.
Unlike what Javadoc: do not insert a <p> tag before a <div> that follows a blank line #268 says, the upstream change applies in block tags; what it leaves out are inline tags and snippets. Here the lexer leaves out
<pre>,<table>,<code>and snippets as before, whose line breaks areFORCED_NEWLINE.Output
Javadoc is formatted only with
JavaFormatterOptions.builder().formatJavadoc(true); neither the command line nor the plugins turn it on.Among the 128k files of JDK 21's
src.zipand the sources jars in the Gradle cache, 17 have a Javadoc line that starts with a<div>. Formatted through the API withformatJavadoc(true), by the old and the newallJar, 7 of them differ, each only by a<p>in front of a<div>that is no longer there, for example injavax/swing/JScrollPane.java:Formatting the output again changes nothing, with either jar.
Tests
noParagraphTagInferredBeforeDivcovers the cases above, in a list item and after@paramtoo, and formats its expected output again. Before the change it fails with<p>in front of each<div>../gradlew checkpasses on JDK 21, 1,439 tests inopen-java-format.