Reputation: 1101
I'm reading the Instrumentation API docs and numerous examples found in web. But still I can't understand what kind of things I can do to a class using Instrumentation API ? Am I right in thinking that before the class is loaded I can do any transformation I want (add new fields, remove, add methods) but once it's loaded I am allowed only to change method bodies ?
Thanks.
Upvotes: 2
Views: 1010
Reputation: 533790
It depends on the JVM as to what changes are allowed. Typically you need to keep the public API and all fields the same. You can change the code.
The retransformation may change method bodies, the constant pool and attributes. The retransformation must not add, remove or rename fields or methods, change the signatures of methods, or change inheritance. These restrictions maybe be lifted in future versions. The class file bytes are not checked, verified and installed until after the transformations have been applied, if the resultant bytes are in error this method will throw an exception.
Upvotes: 1