0 Replies Latest reply on Jun 23, 2013 4:14 PM by navgeet

    IllegalAccessError when using an instrumented class

    navgeet

      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!