Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[java] ClassNamingConventions: interfaces are identified as abstract classes (regression in 7.0.0) #4881

Closed
sdavids opened this issue Mar 23, 2024 · 0 comments · Fixed by #4883
Assignees
Labels
a:bug PMD crashes or fails to analyse a file. a:false-positive PMD flags a piece of code that is not problematic
Milestone

Comments

@sdavids
Copy link

sdavids commented Mar 23, 2024

Affects PMD Version: 7.0.0

Rule: ClassNamingConventions

Description:

An interface should not match ClassNamingConventions.abstractClassPattern.

Code Sample demonstrating the issue:

<rule ref="category/java/codestyle.xml/ClassNamingConventions">
  <properties>
    <property name="abstractClassPattern" value="Abstract[A-Z][a-zA-Z0-9]*"/>
  </properties>
</rule>
public interface TestInterface {
  void test();
}

Steps to reproduce:

No error with 6.55.0:

$ mkdir /tmp/pmd-ClassNamingConventions-regression && cd "$_"
$ mkdir -p gradle/conf src/main/java
$ printf '<?xml version="1.0" encoding="UTF-8"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  name="ClassNamingConventions regression"
  xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
  xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
  <description/>
  <rule ref="category/java/codestyle.xml/ClassNamingConventions">
    <properties>
      <property name="abstractClassPattern" value="Abstract[A-Z][a-zA-Z0-9]*"/>
    </properties>
  </rule>
</ruleset>' > gradle/conf/pmd.xml
$ printf 'rootProject.name = "pmd-ClassNamingConventions-regression"' > settings.gradle.kts
$ printf 'plugins {
  `java-library`
  pmd
}

repositories {
  mavenCentral()
}

pmd {
  toolVersion = "6.55.0"
  ruleSetConfig = resources.text.fromFile("gradle/conf/pmd.xml")
}' > build.gradle.kts
$ printf 'public interface TestInterface { void test(); }' > src/main/java/TestInterface.java
$ gradle wrapper --gradle-version=8.7
$ ./gradlew pmdMain

Update to 7.0.0:

$ printf 'plugins {
  `java-library`
  pmd
}

repositories {
  mavenCentral()
}

dependencies {
  pmd("net.sourceforge.pmd:pmd-ant:7.0.0")
  pmd("net.sourceforge.pmd:pmd-java:7.0.0")
}

pmd {
  toolVersion = "7.0.0"
  ruleSetConfig = resources.text.fromFile("gradle/conf/pmd.xml")
}' > build.gradle.kts
$ ./gradlew pmdMain
> Task :pmdMain FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':pmdMain'.
> A failure occurred while executing org.gradle.api.plugins.quality.internal.PmdAction
   > 1 PMD rule violations were found. See the report at: file:///private/tmp/pmd-ClassNamingConventions-regression/build/reports/pmd/main.html

* Try:
> Run with --scan to get full insights.

BUILD FAILED in 4s
2 actionable tasks: 1 executed, 1 up-to-date
$ cat /private/tmp/pmd-ClassNamingConventions-regression/build/reports/pmd/main.html
<html><head><title>PMD</title></head><body>
<center><h3>PMD report</h3></center><center><h3>Problems found</h3></center><table align="center" cellspacing="0" cellpadding="3"><tr>
<th>#</th><th>File</th><th>Line</th><th>Problem</th></tr>
<tr bgcolor="lightgrey"> 
<td align="center">1</td>
<td width="*%">/private/tmp/pmd-ClassNamingConventions-regression/src/main/java/TestInterface.java</td>
<td align="center" width="5%">2</td>
<td width="*"><a href="https://docs.pmd-code.org/pmd-doc-7.0.0/pmd_rules_java_codestyle.html#classnamingconventions">The interface name 'TestInterface' doesn't match 'Abstract[A-Z][a-zA-Z0-9]*'</a></td>
</tr>
</table></body></html>

7.0.0 with explicit interfacePattern:

$ printf '<?xml version="1.0" encoding="UTF-8"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  name="ClassNamingConventions regression"
  xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
  xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
  <description/>
  <rule ref="category/java/codestyle.xml/ClassNamingConventions">
    <properties>
      <property name="abstractClassPattern" value="Abstract[A-Z][a-zA-Z0-9]*"/>
      <property name="interfacePattern" value="[A-Z][a-zA-Z0-9]*"/>
    </properties>
  </rule>
</ruleset>' > gradle/conf/pmd.xml
$ ./gradlew pmdMain
> Task :pmdMain FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':pmdMain'.
> A failure occurred while executing org.gradle.api.plugins.quality.internal.PmdAction
   > 1 PMD rule violations were found. See the report at: file:///private/tmp/pmd-ClassNamingConventions-regression/build/reports/pmd/main.html

* Try:
> Run with --scan to get full insights.

BUILD FAILED in 4s
2 actionable tasks: 1 executed, 1 up-to-date
$ cat /private/tmp/pmd-ClassNamingConventions-regression/build/reports/pmd/main.html
<html><head><title>PMD</title></head><body>
<center><h3>PMD report</h3></center><center><h3>Problems found</h3></center><table align="center" cellspacing="0" cellpadding="3"><tr>
<th>#</th><th>File</th><th>Line</th><th>Problem</th></tr>
<tr bgcolor="lightgrey"> 
<td align="center">1</td>
<td width="*%">/private/tmp/pmd-ClassNamingConventions-regression/src/main/java/TestInterface.java</td>
<td align="center" width="5%">2</td>
<td width="*"><a href="https://docs.pmd-code.org/pmd-doc-7.0.0/pmd_rules_java_codestyle.html#classnamingconventions">The interface name 'TestInterface' doesn't match 'Abstract[A-Z][a-zA-Z0-9]*'</a></td>
</tr>
</table></body></html>

Running PMD through: Gradle

@sdavids sdavids added the a:bug PMD crashes or fails to analyse a file. label Mar 23, 2024
@adangel adangel added the a:false-positive PMD flags a piece of code that is not problematic label Mar 24, 2024
@adangel adangel added this to the 7.0.1 milestone Mar 24, 2024
@adangel adangel changed the title [java] ClassNamingConventions regression in 7.0.0 [java] ClassNamingConventions: interfaces are identified as abstract classes (regression in 7.0.0) Mar 24, 2024
adangel added a commit to adangel/pmd that referenced this issue Mar 24, 2024
@adangel adangel self-assigned this Mar 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:bug PMD crashes or fails to analyse a file. a:false-positive PMD flags a piece of code that is not problematic
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants