GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [java] UnusedAssignment: False positive when using assert · Issue #5159 · pmd/pmd

[java] UnusedAssignment: False positive when using assert #5159

New issue
Copy link
New issue
Copy link
Closed
#7104
Closed
[java] UnusedAssignment: False positive when using assert#5159
#7104
Copy link
Labels
a:false-positivePMD flags a piece of code that is not problematic
Milestone
7.29.0

Description

@cowwoc
cowwoc
opened on Aug 3, 2024
Issue body actions

Affects PMD Version: 7.4.0

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

Description:

The rule incorrectly assumes that assert statements will always be executed.

Code Sample demonstrating the issue:

{
	boolean assertionsAreEnabled = false;
	//noinspection AssertWithSideEffects
	assert assertionsAreEnabled = true;
	if (assertionsAreEnabled)
		return newInstance(value, name, getAssumeThatConfiguration());
	return MapValidatorNoOp.getInstance();
}

Expected outcome:

PMD reports a violation at line boolean assertionsAreEnabled = false; but that's wrong because if assert is not executed then the assignment is not overwritten.

Running PMD through: [CLI | Ant | Maven | Gradle | Designer | Other]
Maven 3.24.0

Activity

  1. cowwoc
    added
    a:false-positivePMD flags a piece of code that is not problematic
    on Aug 3, 2024
  2. UncleOwen
    added this to the 7.29.0 milestone on Sep 25, 2026
  3. UncleOwen
    closed this as completedin #7104on Sep 25, 2026
  4. UncleOwen
    added a commit that references this issue on Sep 25, 2026

    [java] Fix pmd#5159: UnusedAssignment: an assert statement may not run (

    This issue will close once commit 983d42e is merged into the 'main' branch.
    983d42e
  5. adangel
    changed the title [-][java] UnusedAssignment false positive when using assert[/-] [+][java] UnusedAssignment: false positive when using assert[/+] on Oct 23, 2026
  6. adangel
    changed the title [-][java] UnusedAssignment: false positive when using assert[/-] [+][java] UnusedAssignment: False positive when using assert[/+] on Oct 29, 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-positivePMD flags a piece of code that is not problematic

    Type

    No type

    Projects

    No projects

      Milestone

      • 7.29.0

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.