Skip to content

[java] UselessParentheses: False negative when on the right-hand side of an assignment statement #6775

Closed

Description

@Chordrain

PMD Version: 7.24.0
Category: UselessParentheses
Severity: Warning (Code Style)

Summary

UselessParentheses reports redundant parentheses around the initializer of a variable declaration (double value = (a / b);). The identical redundant parentheses around the right-hand side of a plain assignment statement (value = (a / b);) are not reported. The parentheses are equally useless in both positions — removing them changes neither parsing nor operator precedence.

Reproducer

Before.java (flagged — correct):

public class Before {
    public static void main(String[] argv) {
        int a = Integer.parseInt(argv[0]);
        int b = Integer.parseInt(argv[1]);
        double value = (a / b);
        System.out.println(value);
    }
}

After.java (not flagged — missed):

public class After {
    public static void main(String[] argv) {
        int a; a = Integer.parseInt(argv[0]);
        int b; b = Integer.parseInt(argv[1]);
        double value; value = (a / b);
        System.out.println(value);
    }
}

Expected behavior

Both forms should be reported. The parentheses around a / b are redundant whether a / b is a variable initializer or the right-hand side of an assignment expression.

Actual behavior

Variable-initializer form → 1 violation:

Before.java:5: UselessParentheses: Useless parentheses around `a / b`.

Assignment-statement form → 0 violations. The rule does not inspect the RHS of an AssignmentExpression for useless parentheses, only VariableInitializer.

Activity

  1. added
    a:false-negative
    on Jun 10, 2026
  2. changed the title [-][java] UselessParentheses: not reported on the right-hand side of an assignment statement[/-] [+][java] UselessParentheses: False negative when on the right-hand side of an assignment statement[/+] on Jun 11, 2026
  3. added this to the 7.26.0 milestone on Jun 12, 2026
  4. added a commit that references this issue on Jun 12, 2026
    224d0c4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:false-negative

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions