Skip to content

fix: detect DoubleCheckedLocking with !(x != null) outer guard - #6002

Open
arimu1 wants to merge 1 commit into
google:masterfrom
arimu1:fix/5963-double-checked-locking-negated-ne
Open

fix: detect DoubleCheckedLocking with !(x != null) outer guard#6002
arimu1 wants to merge 1 commit into
google:masterfrom
arimu1:fix/5963-double-checked-locking-negated-ne

Conversation

@arimu1

@arimu1 arimu1 commented Aug 6, 2026

Copy link
Copy Markdown

Fixes #5963

Problem

DoubleCheckedLocking matches the outer null guard by syntax. The
logically equivalent form !(x != null) (instead of x == null) was a
false negative even though the double-checked locking pattern and unsafe
publication on a non-volatile field are unchanged.

Fix

In getNullCheckedExpression, treat a logical complement of a
!= null comparison the same as == null, after stripping parentheses.

Test

  • Added positiveNegatedNotEqualsNull covering the issue reproducer.
  • mvn -pl core -am test -Dtest=DoubleCheckedLockingTest — 8/8 pass (JDK 21/25 toolchains).

DoubleCheckedLocking matched outer null checks only as binary
comparisons. The equivalent form !(x != null) was a false negative.

Normalize LOGICAL_COMPLEMENT of NOT_EQUAL_TO against null the same as
x == null. Fixes google#5963.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[false negative] DoubleCheckedLocking: not reported when the outer null check is written as !(x != null)

1 participant