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] DanglingJavadoc false positive on record compact constructors · Issue #6103 · pmd/pmd

[java] DanglingJavadoc false positive on record compact constructors #6103

New issue
Copy link
New issue
Copy link
Closed
#6112
Closed
[java] DanglingJavadoc false positive on record compact constructors#6103
#6112
Copy link
Labels
a:false-positivePMD flags a piece of code that is not problematic
Milestone
7.18.0

Description

@cowwoc
cowwoc
opened on Sep 30, 2025
Issue body actions

Affects PMD Version: 7.17.0

Rule:

DanglingJavadoc
https://docs.pmd-code.org/pmd-doc-7.17.0/pmd_rules_java_documentation.html#danglingjavadoc

Description:

PMD's DanglingJavadoc rule incorrectly reports Javadoc comments on Java record compact constructors as "dangling" (not belonging to any class, method, or field). Compact constructors are valid constructor declarations introduced in Java 14 (JEP 359) and should be recognized as valid Javadoc targets.

Code Sample demonstrating the issue:

package test;

import static io.github.cowwoc.requirements12.java.DefaultJavaValidators.requireThat;

/**
 * Represents a position in source code with line and column information.
 *
 * @param line the line number (1-based)
 * @param column the column number (1-based)
 */
public record SourcePosition(int line, int column)
{
    /**
     * Compact constructor validating line and column are positive.
     */
    public SourcePosition
    {
        requireThat(line, "line").isPositive();
        requireThat(column, "column").isPositive();
    }
}

Expected outcome:

PMD should recognize the Javadoc comment as documenting the compact constructor and not report any violation.

Actual outcome:

PMD reports a violation at line 15:

Javadoc comment does not belong to any class, method or field

This is a false positive. The Javadoc comment documents the compact constructor public SourcePosition { ... }, which is a valid Java language construct that deserves documentation.

Technical Context:

Java records support compact constructor syntax where the parameter list is omitted:

public record Point(int x, int y) {
    // Compact constructor - no parameter list needed
    public Point {
        if (x < 0 || y < 0) throw new IllegalArgumentException();
        // Field assignments (this.x = x; this.y = y;) are implicit
    }
}

This is equivalent to the canonical constructor form:

public record Point(int x, int y) {
    // Canonical constructor - explicit parameters
    public Point(int x, int y) {
        if (x < 0 || y < 0) throw new IllegalArgumentException();
        this.x = x;
        this.y = y;
    }
}

PMD's DanglingJavadoc rule should recognize ASTCompactConstructorDeclaration as a valid Javadoc target, similar to how it recognizes regular constructor and method declarations.

Running PMD through: Maven (maven-pmd-plugin 3.25.0)

Activity

  1. cowwoc
    added
    a:false-positivePMD flags a piece of code that is not problematic
    on Sep 30, 2025
  2. zbynek commented on Oct 1, 2025

    @zbynek
    zbynek
    on Oct 1, 2025
    Contributor
    More actions

    Thanks, I think I know where the problem is, I hope to have a PR ready soon.

    Reacted by Gili Tzabari
  3. oowekyala
    added this to the 7.18.0 milestone on Oct 19, 2025
  4. oowekyala
    closed this as completedin #6112on Oct 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:false-positivePMD flags a piece of code that is not problematic

    Type

    No type

    Projects

    No projects

      Milestone

      • 7.18.0

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      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.