Affects PMD Version:
6.26.0
Description:
The UnusedAssignment rule flags unused assignments for fields, but the fields might be used in the program flow when invoking methods in between assignments.
Code Sample demonstrating the issue:
Suppose the Worker
class calls the listener in its constructor (it is of course questionable to begin with, but something similar is used in a real-life scenario):
class A implements Worker.Listener { private boolean ignore; private Worker worker; A() { ignore = true; worker = new Worker(this); ignore = false; } void doWork() { worker.work(); } public void onWork() { if (ignore) { return; } System.out.println("onWork"); } }
This reports
A.java:6: The value assigned to field 'ignore' is never used (overwritten on line 8)
Steps to reproduce:
See code sample.
Running PMD through: [CLI | Ant | Maven | Gradle | Designer | Other]
N/A
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4