Skip to content

[java] UnusedAssignment: False positive when assignment is in conditional statement #5940

Closed

Description

@zbynek

Affects PMD Version:
6.55.0, 7.16.0

Rule:
UnusedAssignment

Description:

Code Sample demonstrating the issue:

public class Foo {
    public void process() {
	boolean ok2 = true;
	if (false && (ok2 = false)) {
		return;
	}
	System.out.println(ok2);
    }
}

Since the second assignment of ok2 is never reached, the first one is not redundant.

Expected outcome:

PMD reports a violation at line 3 but that's wrong. That's a false positive.

Running PMD through: Gradle

Activity

  1. added
    a:false-positive
    on Jul 26, 2025
  2. changed the title [-][java] Fallse positive in UnusedAssignment when assignement is in conditional statement[/-] [+][java] False positive in UnusedAssignment when assignement is in conditional statement[/+] on Jul 26, 2025
  3. added 4 commits that reference this issue on Aug 31, 2026
    af3f7a6
    1e1e321
    2ce3004
    00138f3
  4. added a commit that references this issue on Sep 8, 2026
    a1b4165
  5. changed the title [-][java] False positive in UnusedAssignment when assignement is in conditional statement[/-] [+][java] False positive in UnusedAssignment when assignment is in conditional statement[/+] on Sep 8, 2026
  6. added this to the 7.28.0 milestone on Sep 8, 2026
  7. added a commit that references this issue on Sep 8, 2026
    a7a533d
  8. changed the title [-][java] False positive in UnusedAssignment when assignment is in conditional statement[/-] [+][java] UnusedAssignment: False positive when assignment is in conditional statement[/+] on Sep 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:false-positive

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions