GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — [java] Fix #5940: UnusedAssignment FP when constant operand short-circuits the condition by fudianchn · Pull Request #7016 · pmd/pmd Conversation
|
| test | kind | expected | main | this PR |
|---|---|---|---|---|
if (false && (ok2 = false)) (issue sample) |
fix encoder | 0 | 1 | 0 |
if (true || (ok = false)) |
fix encoder | 0 | 1 | 0 |
if (1 == 2 && (ok = false)) |
fix encoder | 0 | 1 | 0 |
if (!true && (ok = false)) |
fix encoder | 0 | 1 | 0 |
if ((false) && (ok = false)) |
fix encoder | 0 | 1 | 0 |
if (false && true && (ok = false)) |
fix encoder | 0 | 1 | 0 |
if (flag || false && (ok = false)) |
fix encoder | 0 | 1 | 0 |
if (DEBUG && (ok = false)) with static final boolean DEBUG = false |
fix encoder | 0 | 1 | 0 |
Foo() { this.f = 1; if (false && (this.f = 2) == 2) ... } (field) |
fix encoder | 0 | 1 | 0 |
while (false && (ok = false)) |
guard | 0 | 0 | 0 |
false && (x = 2) == 2 ? 1 : 2 (ternary) |
guard | 0 | 0 | 0 |
if (false || (ok = false)) |
guard | 1 @l3 | 1 | 1 |
if (true && (ok = false)) |
guard | 1 @l3 | 1 | 1 |
if (false && true || (ok = false)) |
guard | 1 @l3 | 1 | 1 |
if (true || f2(h.getItem())) with initialized local h (LawOfDemeter) |
guard | 1 @L13 | 1 | 1 |
int x = 1; if (false && x > 0) with reportUnusedVariables=true |
opt-in addition | 1 @l3 | 0 | 1 |
The three UnusedAssignment guards expecting a violation pin the evaluated-operand cases (false ||, true &&, constant-false disjunction). With a value-blind mutant that prunes on any constant left operand, exactly these three fail (expected 1, got 0), so they are load-bearing. The LawOfDemeter guard pins the recording of reaching definitions in the skipped operand: a prune that skips exploration without recording fails it with ContextedAssertionError: Should be a blank local variable (the state of the first push), main and this PR both pass it.
Corpus check: UnusedAssignment, ImmutableField, SingularField, LawOfDemeter, AvoidThrowingNullPointerException, ReturnEmptyCollectionRatherThanNull, ImplicitSwitchFallThrough, InvalidLogMessageFormat were run before/after (same driver, main version of DataflowPass first on the classpath for the before run) over java-regression-tests@main (50 files), checkstyle-9.1 src/main/java (412 files), PMD's own pmd-core/pmd-java sources, and the jdk-11+28 com.sun.java.util.jar.pack.Attribute file that produced the regression tester error: 1946 vs 1945 violations, 0 errors on both sides, the only diff is the #5940 sample itself (probe file); Attribute yields the identical 26 findings on both sides. No auxclasspath was configured, so absolute counts can differ from the Regression Tester run, but the before/after comparison is symmetric. The corpus runs use the default configuration, so the reportUnusedVariables=true addition family is not visible there.
FP boundary (probe-verified): the false positive is observable when the then branch completes abruptly and there is no else branch. An if with an else branch, a normally completing then branch, while/for conditions, a ternary condition and do {} while (...) all stay clean on main; the report that remains on do { b = true; } while (false && (b = false)); is a true positive, since the body assignment kills the initializer regardless of the condition.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
bcf47b5 to
af3f7a6
Compare
af3f7a6 to
1e1e321
Compare
There was an error while loading. Please reload this page.
|
Compared to main: (comment created at 2026-09-08 13:10:46+00:00 for 110842a) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
1e1e321 to
2ce3004
Compare
2ce3004 to
00138f3
Compare
There was an error while loading. Please reload this page.
…circuits the condition Signed-off-by: 付典 <[email protected]>
00138f3 to
a1b4165
Compare
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
[java] UnusedAssignment: False positive when assignment is in conditional statement
There was an error while loading. Please reload this page.