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] DoubleCheckedLocking: False negative when the outer null check is written as !(x != null) · Issue #6900 · pmd/pmd

[java] DoubleCheckedLocking: False negative when the outer null check is written as !(x != null) #6900

New issue
Copy link
New issue
Copy link
Closed
#6917
Closed
[java] DoubleCheckedLocking: False negative when the outer null check is written as !(x != null)#6900
#6917
Copy link
Labels
a:false-negativePMD doesn't flag a problematic piece of code
Milestone
7.27.0

Description

@MarkLee131
MarkLee131
opened on Jul 22, 2026
Issue body actions

Affects PMD Version: 7.26.0

Rule: DoubleCheckedLocking
https://docs.pmd-code.org/latest/pmd_rules_java_multithreading.html#doublecheckedlocking

Description:

DoubleCheckedLocking matches the guard by its syntactic form. Writing the outer null check as the logically equivalent !(x != null) instead of x == null makes the rule stop firing, even though the double-checked-locking anti-pattern (and its unsafe publication) is entirely unchanged. Found by metamorphic testing; the same silence reproduces across many double-checked-locking seeds under equivalent guard rewrites.

Code Sample demonstrating the issue:

public class DclSeed {          // reported: DclSeed.java:4 DoubleCheckedLocking
    Object baz;

    Object bar() {
        if (baz == null) {
            synchronized (this) {
                if (baz == null) {
                    baz = new Object();
                }
            }
        }
        return baz;
    }
}
public class DclVariant {       // NOT reported (only LogicInversion fires)
    Object baz;

    Object bar() {
        if (!(baz != null)) {                 // <- equivalent rewrite of `baz == null`
            synchronized (this) {
                if (baz == null) {
                    baz = new Object();
                }
            }
        }
        return baz;
    }
}
$ pmd check -d DclSeed.java,DclVariant.java \
      -R category/java/multithreading.xml/DoubleCheckedLocking -f text
DclSeed.java:4:  DoubleCheckedLocking: Double checked locking is not thread safe in Java.
# (no violation on DclVariant.java)

Expected outcome:

PMD should report a DoubleCheckedLocking violation at DclVariant.java:4 (the outer if), but doesn't. This is a false-negative.

Running PMD through: CLI

Activity

  1. MarkLee131
    added
    a:false-negativePMD doesn't flag a problematic piece of code
    on Jul 22, 2026
  2. adangel
    changed the title [-][java] DoubleCheckedLocking: not reported when the outer null check is written as !(x != null)[/-] [+][java] DoubleCheckedLocking: False negative when the outer null check is written as !(x != null)[/+] on Jul 22, 2026
  3. UncleOwen
    closed this as completedin #6917on Aug 4, 2026
  4. UncleOwen
    added this to the 7.27.0 milestone on Aug 4, 2026
  5. UncleOwen
    added a commit that references this issue on Aug 4, 2026

    [java] Fix pmd#6900: Modifies isNullCheck to accept negated expressio…

    This issue will close once commit 55d2cca is merged into the 'main' branch.
    55d2cca
  6. Will-6543
    added a commit that references this issue on Oct 7, 2026

    [java] Fix pmd#6900: Modifies isNullCheck to accept negated expressio…

    This issue will close once commit f71a964 is merged into the 'main' branch.
    f71a964
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-negativePMD doesn't flag a problematic piece of code

    Type

    No type

    Projects

    No projects

      Milestone

      • 7.27.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.