1 Reply Latest reply on Dec 19, 2009 8:34 AM by derari

    javassist.CannotCompileException when using interfaces

      Hello,

      I could not find a solution for my problem, hopefully someone can help me.

       

      In my project, I am using logging like this:

       

      public interface Logger {
          public void info(String s);  
          public void debug(String s);
      }

      public class LoggerImpl implements Logger {

          // ...

      }

       

      No I want to generate a proxy class that implements Logger, but when I try to compile


      private DynamicProxy dp;
      public void debug (java.lang.String p0) {
          Logger i = (Logger) dp.getImplementation();
          i.debug(p0);
      }

       

      I get "javassist.CannotCompileException: [source error] debug(java.lang.String) not found in dynproxy.test.Logger", whereas

       

      private DynamicProxy dp;
      public void debug (java.lang.String p0) {
           LoggerImpl i = (Logger
      Impl) dp.getImplementation();
           i.debug(p0);
      }

       

      works fine, but is no valid solution for the problem. (The idea is to have a proxy that uses the Logger implementation that is registered with the DynamicProxy object)

       

      So please tell me, what can I do to make it work?

        • 1. Re: javassist.CannotCompileException when using interfaces

          I found it after a lot of trying

           

          the tutorial I was using said

           

          proxyClass.setInterfaces(
                              new CtClass[] { pool.makeClass(iface.getCanonicalName()) });

           

          is the way to extend an Interface, but

           

          proxyClass.setInterfaces(
                               new CtClass[] { pool.get(iface.getCanonicalName()) });

           

          made it work.