diff --git a/jaeger-core/src/main/java/com/uber/jaeger/utils/Java6CompatibleThreadLocalRandom.java b/jaeger-core/src/main/java/com/uber/jaeger/utils/Java6CompatibleThreadLocalRandom.java index e7ab0664a..30b2301b8 100644 --- a/jaeger-core/src/main/java/com/uber/jaeger/utils/Java6CompatibleThreadLocalRandom.java +++ b/jaeger-core/src/main/java/com/uber/jaeger/utils/Java6CompatibleThreadLocalRandom.java @@ -55,14 +55,24 @@ protected Random initialValue() { * * @return the current thread's {@link Random} */ - @IgnoreJRERequirement public static Random current() { if (threadLocalRandomPresent) { - return ThreadLocalRandom.current(); + return ThreadLocalRandomAccessor.getCurrentThreadLocalRandom(); } else { return threadLocal.get(); } } + /** + * This class prevents that {@link ThreadLocalRandom} gets loaded unless + * {@link #getCurrentThreadLocalRandom()} is called + */ + private static class ThreadLocalRandomAccessor { + @IgnoreJRERequirement + private static Random getCurrentThreadLocalRandom() { + return ThreadLocalRandom.current(); + } + } + private Java6CompatibleThreadLocalRandom() {} }