Question

Java Platform SE 5 API specification for method Instrumentation.redefineClasses(ClassDefinition[]) tells:

The redefinition may change method bodies, the constant pool and attributes. The redefinition must not add, remove or rename fields or methods, change the signatures of methods, or change inheritance.

What is meant by attributes? I supposed it can be access modifiers (private, public, ...), synchronized, final and other modifiers. But if I try to redefine not only the method body, but also its access modifier, or access modifier of the class, or try to make a method synchronized, I've got

java.lang.UnsupportedOperationException: class redefinition failed: attempted to change method modifiers
        at sun.instrument.InstrumentationImpl.redefineClasses0(Native Method)
        at sun.instrument.InstrumentationImpl.redefineClasses(Unknown Source)

So what is attributes in this context?

Was it helpful?

Solution

J2SE5 currently only supports the modification on method body and value of fields. If you modify the access modifiers it means you totally change the interface of the class.

For attribute, it is a very vague concept in Java Programming, I have no idea why they put this word into their document. When we say attribute, we mean the Attribute in Java Naming API in most cases.

Redefinition class provide a dynamic way to change the runtime behavior of a existing system. Widely used by AOP I think.

OTHER TIPS

Attributes are pieces of additional information added to classes, methods and fields in the class file. See java vm specification http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.7. There is also a short description of attributes in ASM user guide in Appendix A.3 (http://download.forge.objectweb.org/asm/asm4-guide.pdf).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top