Skip to content

Commit 1a9936b

Browse files
committed
Post-merge tweaks to #85, update release notes
1 parent a892069 commit 1a9936b

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

release-notes/CREDITS

+4
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,7 @@ Paul Galbraith (pgalbraith@github)
131131
* Contributed #73: Add `Generators.defaultTimeBasedGenerator()` to use "default"
132132
interface address for time/based UUIDs
133133
[4.2.0]
134+
135+
Maia Everett (Maia-Everett@github)
136+
* Contributed #85: Fix `LazyRandom` for native code generation tools
137+
[5.0.0]

release-notes/VERSION

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ Releases
77
5.0.0 (not yet released)
88

99
#53: Increase JDK baseline to JDK 8
10+
#85: Fix `LazyRandom` for native code generation tools
11+
(contributed by @Maia-Everett)
1012

1113
4.3.0 (12-Sep-2023)
1214

src/main/java/com/fasterxml/uuid/impl/LazyRandom.java

+5-11
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,20 @@
66
* Trivial helper class that uses class loading as synchronization
77
* mechanism for lazy instantiation of the shared secure random
88
* instance.
9+
*<p>
10+
* Since 5.0 has been lazily created to avoid issues with native-generation
11+
* tools like Graal.
912
*/
1013
public final class LazyRandom
1114
{
1215
private static final Object lock = new Object();
1316
private static volatile SecureRandom shared;
1417

1518
public static SecureRandom sharedSecureRandom() {
16-
// Double check lazy initialization idiom (Effective Java 3rd edition item 11.6)
17-
// Use so that native code generation tools do not detect a SecureRandom instance in a static final field.
18-
SecureRandom result = shared;
19-
20-
if (result != null) {
21-
return result;
22-
}
23-
2419
synchronized (lock) {
25-
result = shared;
26-
20+
SecureRandom result = shared;
2721
if (result == null) {
28-
result = shared = new SecureRandom();
22+
shared = result = new SecureRandom();
2923
}
3024

3125
return result;

0 commit comments

Comments
 (0)