title: Javassist: how to create proxy of proxy?
body: <p>I'm creating proxies with javassist <code>ProxyFactory</code>. When creating a single proxy all works fine.</p>
  
  <p>However, when I pass a proxied object to the proxying mechanism, it fails with</p>
  
  <blockquote>
    <p>javassist.bytecode.DuplicateMemberException: duplicate method: setHandler in com.mypackage.Bean_$$_javassist_0_$$_javassist_1</p>
  </blockquote>
  
  <p>I'm creating the proxies with this:</p>
  
  <pre><code>public Object createProxiedInstance(Object originalInstance) throws Exception {
      Class&lt;?&gt; originalClass = instance.getClass();
      ProxyFactory factory = new ProxyFactory();
  
      factory.setSuperclass(originalClass);
  
      factory.setHandler(new MethodHandler() {..});
      Class&lt;T&gt; proxyClass = factory.createClass();
  
      return proxyClass.newInstance();
  }
  </code></pre>
  
  <p>So, how do I create proxies of proxies?</p>
  
  <p><strong>Update:</strong> The actual problems is that each proxy implements the <code>ProxyObject</code> which defines <code>setHandler(..)</code> method. So the 2nd proxy is trying to redefine the method, instead of overriding it in the subclass.</p>