You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi! Is there a way to detect class is redefined for already loaded class?
As far as I know new fields, methods, and aanotations are forbidden for already loaded classes.
I'm trying to use ByteBuddy(with javaagent) to add the advice to the loaded class which modifies return value of one method.
My target app works on OSGi, and I have to provide transformation logic as a bundle andI want to make transformation of the target class idempotent - avoid double application of the transformation in case of bundle reinstallation.
I use inlining because of OSGi class visibility - target class doesn't see interceptor class(target class loaded with webappCL, and interceptor with BundleCL)
So, I need to detect somehow if the class is already redefined(perfectly I need to get some "version" of the class, but a boolean flag is ok). It's obvious that better is not to keep such info outside of the transformed class)
Or maybe I could somehow preserve original method to be able to restore original state first, before trying to transform it second time. Looking on this way 2 questions I see
1)Is it possible to store original method somehow?
2)Is it possible to order two transformations for same method of the same class? first I need
Thanks!
The text was updated successfully, but these errors were encountered:
While you cannot add any field or method, you can add meta data to any class that you retransform. I would suggest you to add an annotation for your purposes.
One problem with this approach is that you would need to make this annotation type available universally. Otherwise, when Byte Buddy uses the reflection API, where annotations that are not loadable by the respective class loader are suppressed.
If you are using an agent builder, you can however work around this by:
Using a DescriptionStrategy.POOL_ONLY. When Byte Buddy parses a class's description, the same constraint does not apply as for the reflection API.
Implementing a custom PoolStrategy where you return a TypePool.Default and give it a parent type pool of TypePool.Explicit that references all types that are relevant for your annotation.
The original method is not stored by Byte Buddy but it is available by the JVM. If you reapply a retransformation, the retransformation always starts from the base class implementation. You do therefore not need to worry about transformations to apply twice. All transformations are chainable if you for example chain two Advice implementations.
Hi! Is there a way to detect class is redefined for already loaded class?
As far as I know new fields, methods, and aanotations are forbidden for already loaded classes.
I'm trying to use ByteBuddy(with javaagent) to add the advice to the loaded class which modifies return value of one method.
My target app works on OSGi, and I have to provide transformation logic as a bundle andI want to make transformation of the target class idempotent - avoid double application of the transformation in case of bundle reinstallation.
I use inlining because of OSGi class visibility - target class doesn't see interceptor class(target class loaded with webappCL, and interceptor with BundleCL)
So, I need to detect somehow if the class is already redefined(perfectly I need to get some "version" of the class, but a boolean flag is ok). It's obvious that better is not to keep such info outside of the transformed class)
Or maybe I could somehow preserve original method to be able to restore original state first, before trying to transform it second time. Looking on this way 2 questions I see
1)Is it possible to store original method somehow?
2)Is it possible to order two transformations for same method of the same class? first I need
Thanks!
The text was updated successfully, but these errors were encountered: