GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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

@fudianchn fudianchn commented Aug 6, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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.

All reactions
@zbynek
zbynek requested a review from adangel August 7, 2026 15:48
zbynek
zbynek reviewed Aug 7, 2026
View reviewed changes
Comment thread docs/pages/release_notes.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

zbynek
zbynek reviewed Aug 7, 2026
View reviewed changes
Comment thread .../src/test/resources/net/sourceforge/pmd/lang/java/rule/documentation/xml/DanglingJavadoc.xml Resolved

Uh oh!

There was an error while loading. Please reload this page.

zbynek
zbynek reviewed Aug 7, 2026
View reviewed changes
Comment thread .../src/test/resources/net/sourceforge/pmd/lang/java/rule/documentation/xml/DanglingJavadoc.xml Resolved

Uh oh!

There was an error while loading. Please reload this page.

@zbynek

zbynek commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

whether this belongs to this rule specifically or whether /// handling should change in general.

@adangel thoughts?

All reactions

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
@fudianchn
Refer to markdown javadoc as /// in release note and test descriptions
ef8099a
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 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
@fudianchn
fudianchn force-pushed the fix/danglingjavadoc-markdown-java-version-6450 branch from ef8099a to b06b539 Compare August 8, 2026 03:24
@pmd-actions-helper

pmd-actions-helper Bot commented Aug 8, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@fudianchn
fudianchn marked this pull request as draft August 12, 2026 00:37
@fudianchn
fudianchn marked this pull request as ready for review August 12, 2026 16:33
@adangel 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
adangel
adangel reviewed Aug 14, 2026
View reviewed changes

@adangel adangel left a comment

Copy link
Copy Markdown
Member

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.

All reactions
Comment thread docs/pages/release_notes.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

@fudianchn
fudianchn marked this pull request as draft August 15, 2026 01:22
@fudianchn
[java] Fix pmd#6450: Treat /// comments as markdown javadoc only sinc…
5927caf
…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]>
@fudianchn
fudianchn force-pushed the fix/danglingjavadoc-markdown-java-version-6450 branch from b06b539 to 5927caf Compare August 15, 2026 01:34
@fudianchn
fudianchn marked this pull request as ready for review August 15, 2026 01:34
UncleOwen added 3 commits September 10, 2026 13:04
@UncleOwen
fix comment
77f4a07
@UncleOwen
fix which versions to test
c9431bd
@UncleOwen
Merge branch 'main' into fork/fudianchn/fix/danglingjavadoc-markdown-…
b0ce7c2
…java-version-6450

# Conflicts:
#	docs/pages/release_notes.md
@UncleOwen UncleOwen added this to the 7.28.0 milestone Sep 10, 2026
UncleOwen
UncleOwen approved these changes Sep 10, 2026
View reviewed changes

@UncleOwen UncleOwen left a comment

Copy link
Copy Markdown
Member

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.

Thanks!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@UncleOwen
UncleOwen merged commit 73aa712 into pmd:main Sep 10, 2026
13 checks passed

Uh oh!

There was an error while loading. Please reload this page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@zbynek zbynek zbynek left review comments
@adangel adangel adangel left review comments
@UncleOwen UncleOwen UncleOwen approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

7.28.0

Development

Successfully merging this pull request may close these issues.

[java] DanglingJavadoc: False positive on /// comments for Java < 23

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@fudianchn @zbynek @adangel @UncleOwen
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.