From 1a9936b7b44f59f47f7d892acf7c2c8bb90fe07c Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Tue, 24 Oct 2023 20:54:18 -0700 Subject: [PATCH] Post-merge tweaks to #85, update release notes --- release-notes/CREDITS | 4 ++++ release-notes/VERSION | 2 ++ .../java/com/fasterxml/uuid/impl/LazyRandom.java | 16 +++++----------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/release-notes/CREDITS b/release-notes/CREDITS index ecaf1c1..e4315fc 100644 --- a/release-notes/CREDITS +++ b/release-notes/CREDITS @@ -131,3 +131,7 @@ Paul Galbraith (pgalbraith@github) * Contributed #73: Add `Generators.defaultTimeBasedGenerator()` to use "default" interface address for time/based UUIDs [4.2.0] + +Maia Everett (Maia-Everett@github) + * Contributed #85: Fix `LazyRandom` for native code generation tools + [5.0.0] diff --git a/release-notes/VERSION b/release-notes/VERSION index 9b4d337..64add4f 100644 --- a/release-notes/VERSION +++ b/release-notes/VERSION @@ -7,6 +7,8 @@ Releases 5.0.0 (not yet released) #53: Increase JDK baseline to JDK 8 +#85: Fix `LazyRandom` for native code generation tools + (contributed by @Maia-Everett) 4.3.0 (12-Sep-2023) diff --git a/src/main/java/com/fasterxml/uuid/impl/LazyRandom.java b/src/main/java/com/fasterxml/uuid/impl/LazyRandom.java index 5e13e41..b9424d7 100644 --- a/src/main/java/com/fasterxml/uuid/impl/LazyRandom.java +++ b/src/main/java/com/fasterxml/uuid/impl/LazyRandom.java @@ -6,6 +6,9 @@ * Trivial helper class that uses class loading as synchronization * mechanism for lazy instantiation of the shared secure random * instance. + *

+ * Since 5.0 has been lazily created to avoid issues with native-generation + * tools like Graal. */ public final class LazyRandom { @@ -13,19 +16,10 @@ public final class LazyRandom private static volatile SecureRandom shared; public static SecureRandom sharedSecureRandom() { - // Double check lazy initialization idiom (Effective Java 3rd edition item 11.6) - // Use so that native code generation tools do not detect a SecureRandom instance in a static final field. - SecureRandom result = shared; - - if (result != null) { - return result; - } - synchronized (lock) { - result = shared; - + SecureRandom result = shared; if (result == null) { - result = shared = new SecureRandom(); + shared = result = new SecureRandom(); } return result;