Skip to content

[java] New Rule: DanglingJavadoc - #5916

Merged
adangel merged 4 commits into
pmd:mainfrom
zbynek:dangling-javadoc
Sep 11, 2025
Merged

adangel merged 4 commits into
pmd:mainfrom
zbynek:dangling-javadoc

Conversation

@zbynek

@zbynek zbynek commented Jul 18, 2025 •

Copy link
Copy Markdown
Contributor

Describe the PR

Report javadoc not belonging to any class or method.

Related issues

None.

IntelliJ inspection: https://www.jetbrains.com/help/inspectopedia/DanglingJavadoc.html
CheckStyle check: https://checkstyle.sourceforge.io/checks/javadoc/invalidjavadocposition.html
Errorprone check: https://errorprone.info/bugpattern/NotJavadoc

Ready?

  • Added unit tests for fixed bug/feature
  • Passing all unit tests
  • Complete build ./mvnw clean verify passes (checked automatically by github actions)
  • Added (in-code) documentation (if needed)

Questions

  • is this within the scope of PMD, or is it enough that it's handled by CheckStyle?
  • better name ideas?
  • should /// be always treated like Javadoc, even if given project is not using Java 23?

@zbynek
zbynek marked this pull request as draft July 18, 2025 02:26
@zbynek
zbynek force-pushed the dangling-javadoc branch 3 times, most recently from 3fe32c0 to 96821c2 Compare July 18, 2025 18:59
@github-actions

github-actions Bot commented Jul 18, 2025 •

Copy link
Copy Markdown

Documentation Preview

Compared to main:
This changeset changes 0 violations,
introduces 1816 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.

Regression Tester Report

(comment created at 2025-07-18 22:14:18+00:00 for 9d61ef4)

@zbynek
zbynek force-pushed the dangling-javadoc branch from 96821c2 to 9d61ef4 Compare July 18, 2025 21:57
@zbynek
zbynek marked this pull request as ready for review August 27, 2025 21:22
@adangel adangel changed the title [java] new rule: Dangling Javadoc [java] New rule: Dangling Javadoc Sep 8, 2025
@adangel adangel added the a:new-rule Proposal to add a new built-in rule label Sep 9, 2025

@adangel adangel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

is this within the scope of PMD, or is it enough that it's handled by CheckStyle?

Yes, I think so. We have a couple of style related rules in category "Code Style". And the category "Documentation" for this new rule sounds correct as well.

better name ideas?

DanglingJavadoc sounds good. Let's go with that.

should /// be always treated like Javadoc, even if given project is not using Java 23?

I'd say yes. Let's keep it simple for now.


I'll fix the small things myself and merge it afterwards for 7.17.0.

@adangel adangel added this to the 7.17.0 milestone Sep 11, 2025
@pmd-actions-helper

Copy link
Copy Markdown
Contributor

Documentation Preview

Compared to main:
This changeset changes 0 violations,
introduces 2764 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.

Regression Tester Report

(comment created at 2025-09-11 08:26:46+00:00 for 683c820)

@adangel
adangel merged commit 576e682 into pmd:main Sep 11, 2025
@adangel adangel changed the title [java] New rule: Dangling Javadoc [java] New Rule: DanglingJavadoc Sep 12, 2025
fudianchn added a commit to fudianchn/pmd that referenced this pull request Aug 8, 2026
…efore Java 23

DanglingJavadoc reported the new markdown javadoc syntax (///) as
dangling even on Java versions that don't support it (< 23, JEP 467).
Only treat /// as a markdown javadoc comment from Java 23 onwards;
before that it is plain commentary and not dangling.

Addresses zbynek's review:
- release note and test descriptions refer to markdown javadoc as ///
  (not ////).
- scope kept at the rule layer (no parser-level change), aligning with
  the keep-simple decision in pmd#5916; a parser-level /// recognition is
  left for the maintainer to decide.

Signed-off-by: 付典 <[email protected]>
fudianchn added a commit to fudianchn/pmd that referenced this pull request Aug 15, 2026
…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]>
UncleOwen added a commit that referenced this pull request Sep 10, 2026
…) before Java 23 (#6951)

* [java] Fix #6450: Treat /// comments as markdown javadoc only since 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 #5916, see
the discussion in #6450 and #6951.

Signed-off-by: 付典 <[email protected]>

* fix comment

* fix which versions to test

---------

Signed-off-by: 付典 <[email protected]>
Co-authored-by: Sören Glimm <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a:new-rule Proposal to add a new built-in rule

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants