Javassist: how to create proxy of proxy?
Posted
by Bozho
on Stack Overflow
See other posts from Stack Overflow
or by Bozho
Published on 2010-04-11T20:03:47Z
Indexed on
2010/04/11
20:23 UTC
Read the original article
Hit count: 549
I'm creating proxies with javassist ProxyFactory
. When creating a single proxy all works fine.
However, when I pass a proxied class to the proxying mechanism, it fails with
javassist.bytecode.DuplicateMemberException: duplicate method: setHandler in com.mypackage.Bean_$$_javassist_0_$$_javassist_1
I'm creating the proxies with this:
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();
}
So, how do I create proxies of proxies?
Update: The actual problems is that each proxy implements the ProxyObject
which defines setHandler(..)
method. So the 2nd proxy is trying to redefine the method, instead of overriding it in the subclass.
© Stack Overflow or respective owner