Created
June 10, 2025 12:22
-
-
Save scottmarlow/27d346f66847c6e83cbfa980bd691c2e to your computer and use it in GitHub Desktop.
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
| public Class<?> load(Class<?> referenceClass, String className, BiFunction<ByteBuddy, NamingStrategy, DynamicType.Builder<?>> makeClassFunction) { | |
| if (result.getClassLoader() == referenceClass.getClassLoader()) { | |
| try { | |
| return referenceClass.getClassLoader().loadClass(className); | |
| } | |
| catch (ClassNotFoundException e) { | |
| // Ignore | |
| } | |
| } | |
| try { | |
| 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) { | |
| throw new RuntimeException( "Couldn't load or define class [" + className + "]", e ); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment