[jboss-user] [Javassist] - How can get the initial member field value?

Stuart Douglas do-not-reply at jboss.com
Sat Jun 5 22:44:47 EDT 2010


Stuart Douglas [http://community.jboss.org/people/swd847] replied to the discussion

"How can get the initial member field value?"

To view the discussion, visit: http://community.jboss.org/message/546350#546350

--------------------------------------------------------------
This stuff is set in the constructor, so some of it can be extracted, probably not it the format you want though.

For integer fields the bytecode code that gets generated would look something like:

ALOAD_0 //put the this pointer on the stack
ICONST_2 //put the integer constant 2 on the stack
PUTFIELD com/mydomain/Point.x //set the field value.

The hashmap field would be slightly more complex:

ALOAD_0 //put the this pointer on the stack
ANEW java/util/HashMap //create the hashmap instance
DUP //duplicate it so it is still on the stack after the constructor call
INVOKESPECIAL java/util/HashMap.<init> //call the constructor
PUTFIELD com/mydomain/Point.hashMap //set the field value.


To actually extract this information you would need to write some kind of bytecode analyser, and even then there would be cases that it could not handle correctly, as you would also need some kind of dissasembler to go back from the bytecode into java.

--------------------------------------------------------------

Reply to this message by going to Community
[http://community.jboss.org/message/546350#546350]

Start a new discussion in Javassist at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2062]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20100605/d01bd281/attachment.html 


More information about the jboss-user mailing list