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] Renderers output wrong class qualified name for nested classes · Issue #4904 · pmd/pmd

[java] Renderers output wrong class qualified name for nested classes #4904

New issue
Copy link
New issue
Copy link
Closed
#6128
Closed
[java] Renderers output wrong class qualified name for nested classes#4904
#6128
Copy link
Labels
a:bugPMD crashes or fails to analyse a file.
Milestone
7.18.0

Description

@cowwoc
cowwoc
opened on Mar 28, 2024
Issue body actions

Affects PMD Version: 7.0.0

Rule: AbstractClassWithoutAbstractMethod

Description: The AbstractClassWithoutAbstractMethod reports the wrong class

Code Sample demonstrating the issue:

package com.github.cowwoc.lumina;

public final class Form
{
	public static abstract class Property    // <----- Rule is triggering on this line
	{
		// ...
	}

	// ...
}

(https://github.com/cowwoc/lumina/blob/main/java/src/main/java/com/github/cowwoc/lumina/Form.java#L38)

Expected outcome: Violation message with class name com.github.cowwoc.lumina.Form.Property
Actual outcome: [INFO] PMD Failure: com.github.cowwoc.lumina.Property:38 Rule:AbstractClassWithoutAbstractMethod Priority:3 This abstract class does not have any abstract methods.

Running PMD through: Maven

Activity

  1. cowwoc
    added
    a:false-positivePMD flags a piece of code that is not problematic
    on Mar 28, 2024
  2. cowwoc commented on Mar 28, 2024

    @cowwoc
    cowwoc
    on Mar 28, 2024 · Hidden as outdated
    Author
    show commentMore actions
  3. oowekyala commented on May 13, 2024

    @oowekyala
    oowekyala
    on May 13, 2024
    Member
    More actions

    The rule is actually triggered on the following place: https://github.com/cowwoc/lumina/blob/main/java/src/main/java/com/github/cowwoc/lumina/Form.java#L38

    There is a problem with the renderer as it just takes the simple name of the class and prepends the package name. This of course is wrong when the type is a nested class like here. The name of the class is com.github.cowwoc.lumina.Form.Property and not com.github.cowwoc.lumina.Property. Since you have the latter in the package the renderer output is confusing.

    I think the renderer should output file names and not class names, for instance:

    src/main/java/com/github/cowwoc/lumina/Form.java:38 Rule:AbstractClassWithoutAbstractMethod Priority:3 This abstract class does not have any abstract methods.
    

    instead of the current output now (broken)

    com.github.cowwoc.lumina.Property:38 Rule:AbstractClassWithoutAbstractMethod Priority:3 This abstract class does not have any abstract methods.
    

    or "fixed", but it is not obvious which file the line number is for:

    com.github.cowwoc.lumina.Form.Property:38 Rule:AbstractClassWithoutAbstractMethod Priority:3 This abstract class does not have any abstract methods.
    
  4. oowekyala commented on May 13, 2024

    @oowekyala
    oowekyala
    on May 13, 2024
    Member
    More actions

    Here is the problem in the Maven renderer:

    https://github.com/apache/maven-pmd-plugin/blob/c54170707cfd0aec4b5d9ee6083230f2551cdaa4/src/main/java/org/apache/maven/plugins/pmd/PmdViolationCheckMojo.java#L96-L104

    But other renderers in PMD have the same problem, eg

    pmd/pmd-core/src/main/java/net/sourceforge/pmd/renderers/TextColorRenderer.java

    Lines 217 to 219 in e5f55c0

    String packageName = rv.getAdditionalInfo().getOrDefault(RuleViolation.PACKAGE_NAME, "");
    String className = rv.getAdditionalInfo().getOrDefault(RuleViolation.CLASS_NAME, "");
    return StringUtils.isNotBlank(packageName) ? packageName + '.' + className : "";

  5. oowekyala
    changed the title [-][java] AbstractClassWithoutAbstractMethod triggered on non-abstract class[/-] [+][java] Renderers output wrong class qualified name for nested classes[/+] on May 13, 2024
  6. oowekyala
    added
    a:bugPMD crashes or fails to analyse a file.
    and removed
    a:false-positivePMD flags a piece of code that is not problematic
    on May 13, 2024
  7. jsotuyod commented on May 13, 2024

    @jsotuyod
    jsotuyod
    on May 13, 2024
    Member
    More actions

    @adangel I'm unsure this holds for the 3.22.0 plugin version, but you may want to take this to the maven plugin's JIRA.

  8. adangel commented on May 16, 2024

    @adangel
    adangel
    on May 16, 2024
    Member
    More actions

    For nested classes, what are the expected values in additionalinfo of rule violations?

    pmd/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/internal/JavaViolationDecorator.java

    Lines 41 to 42 in 6a328d6

    setIfNonNull(RuleViolation.CLASS_NAME, getClassName(javaNode), additionalInfo);
    setIfNonNull(RuleViolation.PACKAGE_NAME, javaNode.getRoot().getPackageName(), additionalInfo);

    https://docs.pmd-code.org/latest/pmd_languages_java.html#violation-decorators

    Do we miss something here? Like something like "FULLY_QUALIFIED_CLASS_NAME"?

  9. oowekyala commented on May 16, 2024

    @oowekyala
    oowekyala
    on May 16, 2024
    Member
    More actions

    Do we miss something here? Like something like "FULLY_QUALIFIED_CLASS_NAME"?

    Yes. Maybe we can specify CLASS_NAME to mean eg here Form.Property for nested classes though.

  10. adangel
    added this to the 7.18.0 milestone on Sep 12, 2025
  11. adangel
    marked [java] Incorrect class name for public static nested classes reported #5750 as a duplicate of this issue on Oct 10, 2025
  12. adangel
    added 2 commits that reference this issue on Oct 10, 2025

    [java] Fix pmd#4904: Correct class name in violation decorator

    This issue will close once commit aed6ea4 is merged into the 'main' branch.
    aed6ea4

    [java] Fix pmd#4904: Correct class name in violation decorator

    This issue will close once commit c549004 is merged into the 'main' branch.
    c549004
  13. oowekyala
    closed this as completedin c549004on Oct 19, 2025
  14. ppkarwasz
    added 4 commits that reference this issue on Nov 8, 2025

    Bump `commons-parent` to version 92

    d7a7099

    Bump `commons-parent` to version 92

    5d6cb65

    Bump `commons-parent` to version 92

    ae0318c

    Bump `commons-parent` to version 92

    773d203
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:bugPMD crashes or fails to analyse a file.

    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.