A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pmd/pmd/issues/3563 below:

[java] The ClassNamingConventionsRule false-positive's on the class name "Constants" · Issue #3563 · pmd/pmd · GitHub

Affects PMD Version:
6.29.0

Rule:

ClassNamingConventions

Please provide the rule name and a link to the rule documentation:

https://pmd.github.io/latest/pmd_rules_java_codestyle.html#classnamingconventions

Description:

The class name Constants triggers a P1 warning of the ClassNamingConventions rule. From the documentation, the regular expression should be [a-z0-9A-Z]* (notice the star which means "0 or more") but in the code, it uses [a-z0-9A-Z]+ (notice the plus, which means 1 or more).

See https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/ClassNamingConventionsRule.java#L33 where the "+" is defined.

See the documentation where it states:

This rule has the following properties:
...
classPattern [A-Z][a-zA-Z0-9]* Regex which applies to concrete class names

Because of the "+", it effectively requires that there be some prefix in the name. For example, FooConstants, or UhConstants would be valid but Constants is not.

Given the mismatch between the public documentation and the code, I believe this is unintentional.

Code Sample demonstrating the issue:

public class Constants {
   // ...
}

Expected outcome:

PMD reports a violation, but that's wrong. That's a false positive as far as I can see.

Running PMD through: Maven


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