add DEBUG flag save of loaded entity as proxy

Signed-off-by: Scott Marlow <smarlow@redhat.com>
This commit is contained in:
Scott Marlow 2022-09-20 13:57:29 -04:00 committed by Andrea Boriero
parent 744d3ea644
commit ab549a4828
1 changed files with 9 additions and 2 deletions

View File

@ -128,8 +128,15 @@ public final class ByteBuddyState {
* @return The loaded generated class.
*/
public Class<?> load(Class<?> referenceClass, Function<ByteBuddy, DynamicType.Builder<?>> makeClassFunction) {
return make( makeClassFunction.apply( byteBuddy ) )
.load( referenceClass.getClassLoader(), resolveClassLoadingStrategy( referenceClass ) )
Unloaded<?> result = make( makeClassFunction.apply( byteBuddy ) );
if (DEBUG) {
try {
result.saveIn(new File(System.getProperty("java.io.tmpdir") + "/bytebuddy/"));
} catch (IOException e) {
LOG.warn("Unable to save generated class %1$s", result.getTypeDescription().getName(), e);
}
}
return result.load( referenceClass.getClassLoader(), resolveClassLoadingStrategy( referenceClass ) )
.getLoaded();
}