-
-
Notifications
You must be signed in to change notification settings - Fork 845
Description
Hello,I followed the tutorial to simply create a test case,but got a class alreay loaded exception,code as followed:
public static void main(String[] args)
throws NoSuchFieldException {
TypePool typePool = TypePool.Default.ofSystemLoader();
Class<?> cls = new ByteBuddy().redefine(typePool.describe("com.yx.test.bytebuddy.Foo").resolve(),
ClassFileLocator.ForClassLoader.ofSystemLoader()).defineField("qux", String.class)
.make()
.load(ClassLoader.getSystemClassLoader()).getLoaded();
assert cls.getDeclaredField("qux") != null;
}
Exception stack:
Exception in thread "main" java.lang.IllegalStateException: Class already loaded: class com.yx.test.bytebuddy.Foo
at net.bytebuddy.dynamic.loading.ByteArrayClassLoader.load(ByteArrayClassLoader.java:307)
at net.bytebuddy.dynamic.loading.ClassLoadingStrategy$Default$WrappingDispatcher.load(ClassLoadingStrategy.java:357)
at net.bytebuddy.dynamic.loading.ClassLoadingStrategy$Default.load(ClassLoadingStrategy.java:143)
at net.bytebuddy.dynamic.TypeResolutionStrategy$Passive.initialize(TypeResolutionStrategy.java:100)
at net.bytebuddy.dynamic.DynamicType$Default$Unloaded.load(DynamicType.java:5686)
at net.bytebuddy.dynamic.DynamicType$Default$Unloaded.load(DynamicType.java:5675)
at com.yx.test.bytebuddy.Main.main(Main.java:24)
through debug, I found that the classloader is not equal, the bytebuddy version is 1.10.1.
expect your answer,thanks!