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 #4904Labels a:bugPMD crashes or fails to analyse a file. DescriptionAffects 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 Activitycowwoc commented on Mar 28, 2024 Author show commentMore actions oowekyala commented on May 13, 2024 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.
oowekyala commented on May 13, 2024 changed the title [-][java] AbstractClassWithoutAbstractMethod triggered on non-abstract class[/-] [+][java] Renderers output wrong class qualified name for nested classes[/+] on May 13, 2024jsotuyod commented on May 13, 2024 @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. adangel commented on May 16, 2024 For nested classes, what are the expected values in additionalinfo of rule violations?
|
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"? oowekyala commented on May 16, 2024
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. added 2 commits that reference this issue on Oct 10, 2025This issue will close once commit aed6ea4 is merged into the 'main' branch.aed6ea4 This issue will close once commit c549004 is merged into the 'main' branch.c549004
MetadataMetadataa:bugPMD crashes or fails to analyse a file. DevelopmentNo branches or pull requestsIssue actions
|