Skip to content

Commit 01340ca

Browse files
authored
Native image build fails due to CachedSupplier/SplittableRandom (#3768)
- prevents native build having to initialize at buildtime software.amazon.awssdk.utils.cache.CachedSupplier
1 parent 3f877a6 commit 01340ca

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

utils/src/main/java/software/amazon/awssdk/utils/cache/CachedSupplier.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@ public class CachedSupplier<T> implements Supplier<T>, SdkAutoCloseable {
5454
*/
5555
private static final Duration BLOCKING_REFRESH_MAX_WAIT = Duration.ofSeconds(5);
5656

57-
/**
58-
* Random instance used for jittering refresh results.
59-
*/
60-
private static final Random JITTER_RANDOM = new Random();
6157

6258
/**
6359
* Used as a primitive form of rate limiting for the speed of our refreshes. This will make sure that the backing supplier has
@@ -102,6 +98,11 @@ public class CachedSupplier<T> implements Supplier<T>, SdkAutoCloseable {
10298
*/
10399
private final Supplier<RefreshResult<T>> valueSupplier;
104100

101+
/**
102+
* Random instance used for jittering refresh results.
103+
*/
104+
private final Random jitterRandom = new Random();
105+
105106
private CachedSupplier(Builder<T> builder) {
106107
Validate.notNull(builder.supplier, "builder.supplier");
107108
Validate.notNull(builder.jitterEnabled, "builder.jitterEnabled");
@@ -323,7 +324,7 @@ private Duration maxStaleFailureJitter(int numFailures) {
323324

324325
private Instant jitterTime(Instant time, Duration jitterStart, Duration jitterEnd) {
325326
long jitterRange = jitterEnd.minus(jitterStart).toMillis();
326-
long jitterAmount = Math.abs(JITTER_RANDOM.nextLong() % jitterRange);
327+
long jitterAmount = Math.abs(jitterRandom.nextLong() % jitterRange);
327328
return time.plus(jitterStart).plusMillis(jitterAmount);
328329
}
329330

0 commit comments

Comments
 (0)