Skip to content

Commit

Permalink
Post-merge tweaks to #85, update release notes
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Oct 25, 2023
1 parent a892069 commit 1a9936b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
4 changes: 4 additions & 0 deletions release-notes/CREDITS
Original file line number Diff line number Diff line change
Expand Up @@ -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]
2 changes: 2 additions & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
16 changes: 5 additions & 11 deletions src/main/java/com/fasterxml/uuid/impl/LazyRandom.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,20 @@
* Trivial helper class that uses class loading as synchronization
* mechanism for lazy instantiation of the shared secure random
* instance.
*<p>
* Since 5.0 has been lazily created to avoid issues with native-generation
* tools like Graal.
*/
public final class LazyRandom
{
private static final Object lock = new Object();
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;
Expand Down

0 comments on commit 1a9936b

Please sign in to comment.