Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save scottmarlow/13ce48bfda9a0556bb43653aa8acfc97 to your computer and use it in GitHub Desktop.
Save scottmarlow/13ce48bfda9a0556bb43653aa8acfc97 to your computer and use it in GitHub Desktop.
hackretryloadingdefiningloop.java
diff --git a/hibernate-core/src/main/java/org/hibernate/bytecode/internal/bytebuddy/ByteBuddyState.java b/hibernate-core/src/main/java/org/hibernate/bytecode/internal/bytebuddy/ByteBuddyState.java
index 2bdfb646bf..613604561c 100644
--- a/hibernate-core/src/main/java/org/hibernate/bytecode/internal/bytebuddy/ByteBuddyState.java
+++ b/hibernate-core/src/main/java/org/hibernate/bytecode/internal/bytebuddy/ByteBuddyState.java
@@ -237,22 +237,25 @@ public final class ByteBuddyState {
catch (ClassNotFoundException e) {
// Ignore
}
- try {
- return make( makeClassFunction.apply( byteBuddy, new FixedNamingStrategy( className ) ) )
- .load(
- referenceClass.getClassLoader(),
- resolveClassLoadingStrategy( referenceClass )
- )
- .getLoaded();
- }
- catch (LinkageError e) {
+ int tries = 1000;
+ do {
try {
- return referenceClass.getClassLoader().loadClass( className );
- }
- catch (ClassNotFoundException ex) {
- throw new RuntimeException( "Couldn't load or define class [" + className + "]", e );
+ return make(makeClassFunction.apply(byteBuddy, new FixedNamingStrategy(className)))
+ .load(
+ referenceClass.getClassLoader(),
+ resolveClassLoadingStrategy(referenceClass)
+ )
+ .getLoaded();
+ } catch (LinkageError e) {
+ try {
+ return referenceClass.getClassLoader().loadClass(className);
+ } catch (ClassNotFoundException ex) {
+ // will loop again until tries == 0
+ }
}
}
+ while (tries-- > 0);
+ throw new RuntimeException("Couldn't load or define class [" + className + "]");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment