GeezerVison is showing github.com — [java] Fix #6450: DanglingJavadoc should ignore markdown javadoc (///) before Java 23 by fudianchn · Pull Request #6951 · pmd/pmd
Conversation
fudianchn
commented
Aug 6, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
AI disclosure: this change was prepared with AI coding agents, reviewed and revised line by line by me.
What
/// comments are now only treated as markdown javadoc (JEP 467) when the language version is >= Java 23. On older versions they stay ordinary single line comments, which fixes the DanglingJavadoc false positive from #6450.
Why
Since Java 23, /// starts a markdown javadoc comment (JEP 467). Before that, it is an ordinary comment, so flagging it as dangling javadoc is a false positive. This supersedes the "keep it simple for now" decision from #5916 (discussion in #6450), per @adangel's guidance: "it would be more consistent, if the rule only sees the JavadocComments, that are actual Javadoc comments".
Root cause
ASTCompilationUnit#setComments collapsed consecutive /// comments into JavadocComments on all language versions, so the comment model itself classified /// as javadoc even for Java < 23.
How
The parser now passes jdkVersion >= 23 (new grammar helper isMarkdownJavadocSupported) into ASTCompilationUnit#setComments, which collapses markdown comments only when markdown javadoc is supported. DanglingJavadocRule is unchanged: it now only sees actual JavadocComments. Other comment consumers (CommentRequired via getJavadocComment(), UnnecessaryImport, the comment-on XPath function, CommentSize) get the same consistent model.
Testing
- New cases in
DanglingJavadoc.xml: //// under java 21 -> 0 violations (was 1); under java 23 -> 1 violation (unchanged).
- New model-level test
JavaCommentTest#markdownCommentsAreJavadocOnlySinceJava23: at java 21 two /// lines stay two ordinary comments and getJavadocComment() is null; at java 23 they collapse into one JavadocComment owned by the class.
./mvnw -pl pmd-java -am test -Dtest='DanglingJavadocTest,JavaCommentTest,Java23TreeDumpTest' -> 15 passed; full net.sourceforge.pmd.lang.java.ast.** suite -> 2880 passed.
Fixes #6450
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
whether this belongs to this rule specifically or whether /// handling should change in general.
@adangel thoughts?
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
fudianchn
added a commit
to fudianchn/pmd
that referenced
this pull request
Aug 7, 2026
Apply @zbynek's review suggestions on pmd#6951: describe the canonical
markdown javadoc marker as `///` rather than `////` in the release
note and the two new test-case descriptions. The test sources keep `////`
to exercise that an extra leading slash still counts as markdown javadoc.
Signed-off-by: 付典 <[email protected]>
zbynek
changed the title
[java] Fix #6450: DanglingJavadoc ignores markdown javadoc (////) before Java 23
[java] Fix #6450: DanglingJavadoc ignores markdown javadoc (///) before Java 23
Aug 7, 2026
|
Documentation Preview
Compared to main:
This changeset changes 0 violations,
introduces 0 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
There are 0 changed duplications, 0 new duplications and 0 removed duplications.
There are 0 changed CPD errors, 0 new CPD errors and 0 removed CPD errors.
Regression Tester Report
(comment created at 2026-09-10 11:35:45+00:00 for b0ce7c2)
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
adangel
changed the title
[java] Fix #6450: DanglingJavadoc ignores markdown javadoc (///) before Java 23
[java] Fix #6450: DanglingJavadoc should ignore markdown javadoc (///) before Java 23
Aug 14, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whether this belongs to this rule specifically or whether /// handling should change in general.
@adangel thoughts?
Indeed, it would be more consistent, if the rule only sees the JavadocComments, that are actual Javadoc comments.
@fudianchn Can you give it a try? The implementation is in ASTCompilationUnit#setComments. There you also can check the language version.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
…e Java 23
Markdown documentation comments (JEP 467) are available since Java 23.
ASTCompilationUnit#setComments now collapses consecutive /// comments
into JavadocComments only when the language version is >= 23, so on
older versions they stay ordinary single line comments and are no
longer reported by DanglingJavadoc. Other comment consumers see the
same consistent model.
This supersedes the "keep it simple for now" decision from pmd#5916, see
the discussion in pmd#6450 and pmd#6951.
Signed-off-by: 付典 <[email protected]>
…java-version-6450
# Conflicts:
# docs/pages/release_notes.md
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Reviewers
zbynek
zbynek left review comments
adangel
adangel left review comments
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
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.
|