I'm using the following code to create a proxy:
public Object createProxiedInstance(Object originalInstance) throws Exception {
Class<?> originalClass = instance.getClass();
ProxyFactory factory = new ProxyFactory();
factory.setSuperclass(originalClass);
factory.setHandler(new MethodHandler() {..});
Class<T> proxyClass = factory.createClass();
return proxyClass.newInstance();
}
It works fine if a pass a normal object. However, if I pass an object that is already a proxy (created by the same method, but with a different method handler), I get:
javassist.bytecode.DuplicateMemberException: duplicate method: setHandler in com.mypackage.Bean_$$_javassist_0_$$_javassist_1
I could work this around by combining the method handler of the original proy and the one of the new proxy, but is there a way to make proxies of proxies, as if the proxies were normal objects?