A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pmd/pmd/issues/5504 below:

[java] UnusedAssignment false-positive in for-loop with continue · Issue #5504 · pmd/pmd · GitHub

Affects PMD Version:
7.10.0

Rule:
https://docs.pmd-code.org/latest/pmd_rules_java_bestpractices.html#unusedassignment

Code Sample demonstrating the issue:

List<String> lines = Files.readAllLines("someFile");
int lineNumber = 0;
boolean expectingAnotherLine = false;
for (String line : lines)
{
	++lineNumber;
	if (line.endsWith("\\"))
	{
		expectingAnotherLine = true; // line 9 - false positive unused assignment
		continue;
	}
	expectingAnotherLine = false;
}
if (expectingAnotherLine)
	throw new IllegalArgumentException("Unexpected end of line: " + command);

Expected outcome:

PMD reports a violation at line 9 (expectingAnotherLine = true;), but that's wrong. That's a false positive.

Running PMD through:
Maven plugin 3.26.0


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