I am trying to redefine 2 methods using ByteBuddy, like so:
ClassLoader classLoader = ClassLoader.getSystemClassLoader();
ClassLoadingStrategy.Default classLoadingStrategy = ClassLoadingStrategy.Default.INJECTION;
new ByteBuddy().redefine(CommandBase.class).method(returns(Item.class)).intercept(MethodDelegation.to(CppItemInterceptor.class)).make().load(classLoader, classLoadingStrategy);
new ByteBuddy().redefine(CommandBase.class).method(returns(Block.class)).intercept(MethodDelegation.to(CppBlockInterceptor.class)).make().load(classLoader, classLoadingStrategy);
try {
System.out.println(CppBlockInterceptor.getBlockByText(null, "1").getLocalizedName());
System.out.println(CommandBase.getBlockByText(null, "1").getLocalizedName());
} catch (Exception e) {
e.printStackTrace();
}
The direct call to CppBlockInterceptor produces the intended output, but the call to the method that was supposed to be replaced still uses the old behavior. Is there any reason for this?