[java] ClassNamingConventions uses wrong pattern for interfaces
zman0900 opened this issue · comments
Dan Ziemba commented
Affects PMD Version: 7.0.0
Description:
When the ClassNamingConventions rule is configured with a custom naming pattern for abstract classes, it reports all interfaces as in violation of that rule.
Dumping AST for an interface shows that they all seem to be also marked as abstract.
<ClassDeclaration Abstract='true' Annotation='false' Anonymous='false' BinaryName='sample.Example' CanonicalName='sample.Example' EffectiveVisibility='public' Enum='false' Final='false' Image='' Interface='true' Local='false' Nested='false' PackageName='sample' Record='false' RegularClass='false' RegularInterface='true' SimpleName='Example' Static='false' TopLevel='true' Visibility='public'>
Code Sample demonstrating the issue:
package sample;
public interface Example {
}
<rule ref="category/java/codestyle.xml/ClassNamingConventions">
<properties>
<property name="abstractClassPattern" value="Abstract[a-zA-Z0-9]+" />
</properties>
</rule>
Steps to reproduce:
- Configure rules file as above with custom pattern for abstract classes.
- Have an interface that does not meet that pattern.
- Get violation like:
PMD Failure: sample.Example:3 Rule:ClassNamingConventions Priority:1 The interface name 'Example' doesn't match 'Abstract[a-zA-Z0-9]+'.
Running PMD through: Maven
Juan Martín Sotuyo Dodero commented
This is weird… the rule explicitly checks for interfaces beforehand…
Dan Ziemba commented