|
From: Rob H. <ro...@ca...> - 2004-10-06 09:44:51
|
Chris,
I took a look at your suggested workaround and I started the basics of
an implementation. The problem I came up against is that when the
constructor is invoked by CGLIB, which in turn invokes a method, say
setName(), the call to invokeSuper() by the interceptor fails with:
net.sf.cglib.core.CodeGenerationException:
java.lang.ClassCastException-->null
at net.sf.cglib.core.ReflectUtils.newInstance(ReflectUtils.java:235)
at net.sf.cglib.core.ReflectUtils.newInstance(ReflectUtils.java:220)
at net.sf.cglib.core.ReflectUtils.newInstance(ReflectUtils.java:216)
at net.sf.cglib.proxy.Enhancer.createUsingReflection(Enhancer.java:566)
at net.sf.cglib.proxy.Enhancer.firstInstance(Enhancer.java:493)
at
net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:220)
at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer.java:368)
at net.sf.cglib.proxy.Enhancer.create(Enhancer.java:280)
at
org.springframework.aop.framework.Cglib2AopProxy.getProxy(Cglib2AopProxy.java:178)
at
org.springframework.aop.framework.Cglib2AopProxy.getProxy(Cglib2AopProxy.java:142)
at
org.springframework.aop.framework.CglibProxyTests.testFoo(CglibProxyTests.java:144)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:421)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186)
Caused by: java.lang.ClassCastException
at
org.springframework.aop.framework.CglibTestBean$$EnhancerByCGLIB$$5c148601$$FastClassByCGLIB$$7660a3f6.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:167)
at
org.springframework.aop.framework.Cglib2AopProxy$MethodInvocationImpl.invokeJoinpoint(Cglib2AopProxy.java:914)
at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:119)
at
org.springframework.aop.interceptor.NopInterceptor.invoke(NopInterceptor.java:39)
at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:141)
at
org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:629)
at
org.springframework.aop.framework.CglibTestBean$$EnhancerByCGLIB$$5c148601.setName(<generated>)
at
org.springframework.aop.framework.CglibTestBean.<init>(CglibTestBean.java:14)
at
org.springframework.aop.framework.CglibTestBean$$EnhancerByCGLIB$$5c148601.<init>(<generated>)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown
Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at net.sf.cglib.core.ReflectUtils.newInstance(ReflectUtils.java:228)
... 25 more
I'm a little lost at this point, any help you could give would be much
appreciated :)
Rob
Chris Nokleberg wrote:
>Rod Johnson wrote:
>
>
>>Your analysis looked right to me. Unfortunate. There are certainly quite
>>a few negative consequences of the CGLIB subclassing approach. It would
>>be good if there were other options we could consider when proxying
>>classes (the AopProxyFactory interface gives us a choice), but I'm not
>>aware of anything that's equally convenient.
>>
>>
>
>I've posted a comment on how to work around this "feature" of CGLIB (it is a
>feature, really :-)
>
>If you want to proxy concrete classes your options are pretty limited, I
>think. One possibility you may not be aware of is that if you are proxying
>JavaBeans you could use net.sf.cglib.beans.BeanGenerator to generate a bean
>that has the same properties as your target bean. Then use the Enhancer to
>proxy the generated bean, dispatching to the target as appropriate. This
>way you avoid all issues with the superclass constructor being invoked,
>since the generated bean extends Object. Let me know if you want to explore
>this further.
>
>Chris
>
>
>
>
>-------------------------------------------------------
>This SF.net email is sponsored by: IT Product Guide on ITManagersJournal
>Use IT products in your business? Tell us what you think of them. Give us
>Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more
>http://productguide.itmanagersjournal.com/guidepromo.tmpl
>_______________________________________________
>Springframework-developer mailing list
>Spr...@li...
>https://lists.sourceforge.net/lists/listinfo/springframework-developer
>
>
>
>
|