Skip to content

[java] AvoidLiteralsInIfCondition: false negative for expressions #2140

@linusjf

Description

@linusjf

Affects PMD Version:
Running against 6.19.0,6.20.0.

Rule:
AvoidLiteralsInIfCondition

Description:
Expression with constants sidesteps this rule. The rule is configured with allowed values: -1,0,1.

Code Sample demonstrating the issue:

package pmdtests;

public enum MulticastSender {
;

 private static byte getTTL(String... args) {
    try {
      if (args.length > (1 + 1))
        return (byte)Integer.parseInt(args[2]);
    } catch (NumberFormatException e) {
      // empty catch block
    }
    return (byte)1;
  }

}

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:false-negativePMD doesn't flag a problematic piece of code

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions