Skip to content

Commit

Permalink
Make checks for existence of ThreadLocal more robust (#1136)
Browse files Browse the repository at this point in the history
We should try to load an actual value of a ThreadLocal, because
in some environments (like WebLogic) a `NoClassDefException` won't
be thrown during loading of `JdkProvider`.

We should also catch all possible errors, not only `NoClassDefException`
to avoid a situation when the provider becomes a null reference.

(cherry picked from commit 469600d)
  • Loading branch information
arteam committed Jun 2, 2017
1 parent 8b2277f commit b850427
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Expand Up @@ -97,7 +97,7 @@ private static Provider getLongAdderProvider() {
final JdkProvider jdkProvider = new JdkProvider();
jdkProvider.get(); // To trigger a possible `NoClassDefFoundError` exception
return jdkProvider;
} catch (NoClassDefFoundError e) {
} catch (Throwable e) {
return new InternalLongAdderProvider();
}
}
Expand Down
Expand Up @@ -35,8 +35,10 @@ public Random current() {
private static final Provider INSTANCE = getThreadLocalProvider();
private static Provider getThreadLocalProvider() {
try {
return new JdkProvider();
} catch (NoClassDefFoundError e) {
final JdkProvider jdkProvider = new JdkProvider();
jdkProvider.current(); // To make sure that ThreadLocalRandom actually exists in the JDK
return jdkProvider;
} catch (Throwable e) {
return new InternalProvider();
}
}
Expand Down

0 comments on commit b850427

Please sign in to comment.