[jboss-user] [Javassist] - Is is possible to instrument java core classes? Classes loaded by the bootstrap classloader

Rodrigo Uchoa do-not-reply at jboss.com
Thu Mar 8 08:56:00 EST 2012


Rodrigo Uchoa [https://community.jboss.org/people/rodrigo.uchoa] created the discussion

"Is is possible to instrument java core classes? Classes loaded by the bootstrap classloader"

To view the discussion, visit: https://community.jboss.org/message/722476#722476

--------------------------------------------------------------
Hello!

I want to add an "insertBefore" on a method of a core JDK 5 class. For some reason it´s not working. Here's the code:


ClassPool pool = ClassPool.getDefault();
CtClass ctClass = pool.get("com.sun.org.apache.xerces.internal.impl.xs.XSMessageFormatter");
CtMethod ctMethod = ctClass.getDeclaredMethods()[0];
ctMethod.insertBefore("System.out.println(\"WORKED\");");
ctClass.toClass();



The +com.sun.org.apache.xerces.internal.impl.xs.XSMessageFormatter+ comes bundled with the JDK, it's inside rt.jar. After the snippet above, I run some code that forces the XSMessageFormatter class to run, but my inserted code never runs. I can only get this to work on my own classes. This code is running as a simple standalone app.

Any ideas?
--------------------------------------------------------------

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

Start a new discussion in Javassist at Community
[https://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/20120308/16010e92/attachment.html 


More information about the jboss-user mailing list