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
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4