JBoss Community

IllegalAccessError when using an instrumented class

created by Navgeet Agrawal in Javassist - View the full discussion

Hi all,

 

I am trying to instrument https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Compiler.java

I am using the following code:

 

ClassPool cp = ClassPool.getDefault();

CtClass ctClazz = cp.get("clojure.lang.Compiler");

ctClazz.addMethod(CtNewMethod.make("public String foo (){return \"foo\"; }", ctClazz));

return ctClazz.toClass();

 

I am calling getDeclaredMethod on the returned class and invoke on the method to call foo() which throws:

 

IllegalAccessError tried to access class clojure.lang.Compiler$DefExpr$Parser from class clojure.lang.Compiler  clojure.lang.Compiler.<clinit>

(Compiler.java:102)

 

Javassist's docs state that it does not work with inner classes, which I suspect to be the problem here.

Or rather it could be a ClassLoader problem. Unfortunately I know little about classloaders.

Any pointers would be appreciated.

 

Thanks!

Reply to this message by going to Community

Start a new discussion in Javassist at Community