Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Wolf2323 opened this issue May 14, 2024 · 0 comments
Labels
a:false-positive PMD flags a piece of code that is not problematic

Comments

@Wolf2323
Copy link

Wolf2323 commented May 14, 2024

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

@Wolf2323 Wolf2323 added the a:false-positive PMD flags a piece of code that is not problematic label May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:false-positive PMD flags a piece of code that is not problematic
Projects
None yet
Development

No branches or pull requests

1 participant