You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[java] DoubleCheckedLocking: False negative when the outer null check is written as !(x != null) #6900
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.
publicclassDclVariant { // NOT reported (only LogicInversion fires)Objectbaz;
Objectbar() {
if (!(baz != null)) { // <- equivalent rewrite of `baz == null`synchronized (this) {
if (baz == null) {
baz = newObject();
}
}
}
returnbaz;
}
}
$ 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.
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
Activity
[-][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)[/+][java] Fix pmd#6900: Modifies isNullCheck to accept negated expressio…
[java] Fix pmd#6900: Modifies isNullCheck to accept negated expressio…