Find double-checked locking on a non-volatile field

Proprietary

Finds the classic double-checked locking pattern — an outer if (field == null) guarding a synchronized block that contains an inner if (field == null) { field = new ...(); } — where the field is not declared volatile and the enclosing method is not synchronized. Prior to Java 5 (and still on older JVMs) another thread can observe a partially-constructed object through the outer check, skipping the lock. Prefer a synchronized accessor or the static-holder idiom; if you keep DCL, declare the field volatile.

org.openrewrite.java.security.search.FindDoubleCheckedLocking
mod run . --recipe=org.openrewrite.java.security.search.FindDoubleCheckedLocking

Install it once from Recipe actions, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.