Created
June 16, 2025 20:56
-
-
Save scottmarlow/13ce48bfda9a0556bb43653aa8acfc97 to your computer and use it in GitHub Desktop.
hackretryloadingdefiningloop.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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