-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Description
Description
Another one for you, guys
It looks like the usage of double check will not work reliably in a platform independent way when implemented in Java.
Writes that initialize the object and the write to the helper field can be done or perceived out of order.
Even if the compiler does not reorder those writes, on a multiprocessor the processor or the memory system may reorder those writes, as perceived by a thread running on another processor.
Discussion
No response
Motivation
No response
Details
I think it's worth reviewing the following double check blocks:
keycloak/services/src/main/java/org/keycloak/credential/WebAuthnCredentialProviderFactory.java
Lines 37 to 39 in 7fac153
if (converter == null) { | |
synchronized (this) { | |
if (converter == null) { |
2nd:
keycloak/services/src/main/java/org/keycloak/services/resources/WelcomeResource.java
Lines 262 to 264 in 7fac153
if (shouldBootstrap == null) { | |
synchronized (this) { | |
if (shouldBootstrap == null) { |
3rd:
keycloak/services/src/main/java/org/keycloak/theme/freemarker/DefaultFreeMarkerProviderFactory.java
Lines 19 to 21 in 7fac153
if (provider == null) { | |
synchronized (this) { | |
if (provider == null) { |
4th:
Lines 42 to 44 in 7fac153
if (converter == null) { | |
synchronized (this) { | |
if (converter == null) { |
Suggest using volatile variables.
JDK5 and later extends the semantics for volatile so that the system will not allow a write of a volatile to be reordered with respect to any previous read or write, and a read of a volatile cannot be reordered with respect to any following read or write.
Took the information from the source: https://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html
Found by Linux Verification Center with SVACE