Repository navigation
[java] Fix #6450: DanglingJavadoc should ignore markdown javadoc (///) before Java 23 - #6951
Conversation
@adangel thoughts? |
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]>
ef8099a to
b06b539
Compare
|
Compared to main: (comment created at 2026-09-10 11:35:45+00:00 for b0ce7c2) |
adangel
left a comment
There was a problem hiding this comment.
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.
…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]>
b06b539 to
5927caf
Compare
…java-version-6450 # Conflicts: # docs/pages/release_notes.md
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 theDanglingJavadocfalse 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#setCommentscollapsed consecutive///comments intoJavadocComments 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 helperisMarkdownJavadocSupported) intoASTCompilationUnit#setComments, which collapses markdown comments only when markdown javadoc is supported.DanglingJavadocRuleis unchanged: it now only sees actualJavadocComments. Other comment consumers (CommentRequiredviagetJavadocComment(),UnnecessaryImport, thecomment-onXPath function,CommentSize) get the same consistent model.Testing
DanglingJavadoc.xml:////underjava 21-> 0 violations (was 1); underjava 23-> 1 violation (unchanged).JavaCommentTest#markdownCommentsAreJavadocOnlySinceJava23: atjava 21two///lines stay two ordinary comments andgetJavadocComment()is null; atjava 23they collapse into oneJavadocCommentowned by the class../mvnw -pl pmd-java -am test -Dtest='DanglingJavadocTest,JavaCommentTest,Java23TreeDumpTest'-> 15 passed; fullnet.sourceforge.pmd.lang.java.ast.**suite -> 2880 passed.Fixes #6450