Skip to content

[java] UnusedAssignment - false-positive boolean flag for execution and reset in finally #5016

Open
@Wolf2323

Description

@Wolf2323

Affects PMD Version: 7.1.0

Rule: UnusedAssignment

Description:
a flag set in a method, and directly reset after executing some code causes a UnusedAssignment since PMD 7. In PMD 6 this was no issue

Code Sample demonstrating the issue:

	@Override
	public void run(@NotNull final Runnable runnable) {
		if (entered || conflict) {
			return;
		}
		try {
			entered = true;
			runnable.run();
		} finally {
			entered = false;
		}
	}

Expected outcome:
This should be fine as the runnable can get the set flag and can access the method again.

[INFO] PMD Failure: works.reload.relogic.recursion.RecursionGuardImpl:56 Rule:UnusedAssignment Priority:3 The value assigned to field 'entered' is never used (overwritten on line 59).

Running PMD through: Maven

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:false-positivePMD flags a piece of code that is not problematic

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions