Modifying with FixedValue.value for another class

11 views
Skip to first unread message

Datson Yan

unread,
Jul 12, 2025, 2:37:03 PMJul 12
to Byte Buddy
Hey very quick and noob question since I am still relatively new to ASM and ByteBuddy.

in my class ModifyMe.java, the method hello() returns a String "Original from method hello".

The interceptor with ByteBuddy works correctly but it seems to still execute the original method from ModifyMe and it returns the string from that method.

Class<? extends ModifyMe> loaded = new ByteBuddy().subclass(ModifyMe.class)
.method(ElementMatchers.named("hello"))
.intercept(FixedValue.value("Hello World! I have been dynamically modified!"))
.make()
.load(getClass().getClassLoader())
.getLoaded();


ModifyMe byteBuddyModifyMe = loaded.getDeclaredConstructor(String.class)
.newInstance("former glory");
System.out.println(byteBuddyModifyMe.hello());


The example with Object.class works fine.

Rafael Winterhalter

unread,
Jul 13, 2025, 3:12:19 AMJul 13
to Datson Yan, Byte Buddy

Is ModifyMe package private by any chance, possibly the method itself?

In this case, the method is not dispatched virtually, if in different class loaders as it would be by default? That's a little known JVM feature, but it might explain what you experience.


--
You received this message because you are subscribed to the Google Groups "Byte Buddy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to byte-buddy+...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/byte-buddy/41729f1d-0030-484c-b44d-fbb81aab3b42n%40googlegroups.com.
Reply all
Reply to author
Forward
Message has been deleted
0 new messages