Skip to content

[java] Regression with LiteralsFirstInComparisons in 6.35.0 #3352

@hgschmie

Description

@hgschmie

Affects PMD Version:

6.35.0

Rule:

LiteralsFirstInComparisons

Please provide the rule name and a link to the rule documentation:
https://pmd.github.io/latest/pmd_rules_java_bestpractices.html#literalsfirstincomparisons

Description:

PMD 6.35.0 shows a regression by reporting the following issue.

Code Sample demonstrating the issue:

https://github.com/jdbi/jdbi/blob/master/core/src/main/java/org/jdbi/v3/core/statement/DescribedArgument.java#L52

if (Boolean.TRUE.equals(ARG_CLASS_HAS_TOSTRING.get(arg.getClass(), ctx))) {

Expected outcome:

No error message

PMD reports a violation at line ..., but that's wrong. That's a false positive.

[INFO] --- maven-pmd-plugin:3.14.0:check (default-cli) @ jdbi3-core ---
[INFO] PMD version: 6.35.0
[INFO] PMD Failure: org.jdbi.v3.core.statement.DescribedArgument:52 Rule:LiteralsFirstInComparisons Priority:3 Position literals first in String comparisons.
[INFO] PMD Failure: org.jdbi.v3.core.statement.DescribedArgument:52 Rule:LiteralsFirstInComparisons Priority:3 Position literals first in String comparisons.

Full test case:

git clone 	git@github.com:jdbi/jdbi.git
cd jdbi
mvn -Dbasepom.check.skip-all=true -DskipTests -Dbasepom.check.skip-pmd=false clean install

==> succeeds

mvn -Ddep.pmd.version=6.35.0 -Dbasepom.check.skip-all=true -DskipTests -Dbasepom.check.skip-pmd=false clean install

fails:

[INFO] --- maven-pmd-plugin:3.14.0:check (default) @ jdbi3-core ---
[INFO] PMD version: 6.35.0
[...]
[INFO] PMD Failure: org.jdbi.v3.core.statement.DescribedArgument:52 Rule:LiteralsFirstInComparisons Priority:3 Position literals first in String comparisons.
[...]
[INFO] PMD Failure: org.jdbi.v3.core.statement.DescribedArgument:52 Rule:LiteralsFirstInComparisons Priority:3 Position literals first in String comparisons.

(please ignore the CognitiveComplexity problems)

Running PMD through: [CLI | Ant | Maven | Gradle | Designer | Other]

maven

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:false-positivePMD flags a piece of code that is not problematic

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions