Repository navigation
Description
Error Prone version
Error Prone 2.49.0 (javac 21.0.8, --source/--target 21)
Affected checks
AssignmentExpression
Description
AssignmentExpression produces different findings when redundant parentheses are added to or removed from an inner assignment. For example, a = b = 0 is not flagged, while a = (b = 0) is flagged. Similarly, result = (bresult = new byte[len]) is flagged, while result = bresult = new byte[len] is not. The reproducer also includes unchanged findings and non-findings to show the result at each assignment site.
Per JLS §15.8.5, parentheses around an expression do not change its value, type, or constant-expression status. Adding or removing these parentheses should therefore not change the check's findings at the corresponding sites.
I verified the following pair on Error Prone 2.49.0:
| Check | Rewrite | BEFORE | AFTER | Effect |
|---|---|---|---|---|
AssignmentExpression |
a = b = 0 ↔ a = (b = 0) and the related sites below |
2 | 3 | verdict drift as parentheses are added/removed |
The matcher appears to depend on ParenthesizedTree nodes around assignments. A possible fix is to account for redundant parentheses when inspecting the assignment expression and its enclosing context, for example by using ASTHelpers.stripParentheses where appropriate.
Reproducers
AssignmentExpression — verdict is not parenthesis-invariant
The check flags an assignment used inside a larger expression, but the result depends on redundant parentheses around the inner assignment — in both directions: a = b = 0 is not flagged while a = (b = 0) is, whereas result = (bresult = new byte[len]) is flagged while result = bresult = new byte[len] is not.
// BEFORE — 2 findings (on `int i = j = 0;` and `result = (bresult = ...)`)
public class Sample {
int a, b, j, l;
byte[] bresult;
void m1() { a = b = 0; } // NOT flagged
void m2() { if ((a = b = 0) != 1) {} } // NOT flagged
void m3() { int i = j = 0; } // flagged
void m4(int len) {
int k = (l += 1); // NOT flagged
byte[] result;
result = (bresult = new byte[len]); // flagged
}
}// AFTER — 3 findings; per-site verdicts flip as parentheses are added/removed
public class Sample {
int a, b, j, l;
byte[] bresult;
void m1() { a = (b = 0); } // now flagged
void m2() { if ((a = (b = 0)) != 1) {} } // now flagged
void m3() { int i = (j = 0); } // flagged
void m4(int len) {
int k = l += 1; // NOT flagged
byte[] result;
result = bresult = new byte[len]; // now NOT flagged
}
}Expected behavior
The BEFORE and AFTER versions should produce the same findings at each corresponding assignment site. Adding or removing redundant parentheses around an inner assignment should not change whether that site is reported.
Actual behavior
The BEFORE version produces 2 findings, while the AFTER version produces 3. The findings change at individual sites as follows:
| Site | BEFORE | AFTER |
|---|---|---|
m1: a = b = 0 → a = (b = 0) |
Not flagged | Flagged |
m2: if ((a = b = 0) != 1) → if ((a = (b = 0)) != 1) |
Not flagged | Flagged |
m3: int i = j = 0 → int i = (j = 0) |
Flagged | Flagged |
m4: int k = (l += 1) → int k = l += 1 |
Not flagged | Not flagged |
m4: result = (bresult = new byte[len]) → result = bresult = new byte[len] |
Flagged | Not flagged |
The overall count hides changes in both directions: two sites gain findings when parentheses are added, while one site loses its finding when parentheses are removed.
Activity
cushon commentedon Nov 4, 2026
Thanks for the report.
AssignmentExpressiononly exempts direct chained assignments likex = y = 0and single-parenthesized binary condition idioms likeif ((x = foo()) != null), and we don't plan to expand that exemption to arbitrarily parenthesized assignments (see https://errorprone.info/docs/criteria#false-positives-false-negatives-and-bug-reports).