Results 1 to 2 of 2

Thread: Creating mixin fails if target has no default constructor

  1. #1
    Join Date
    Nov 2004
    Location
    Zurich [CH]
    Posts
    14

    Default Creating mixin fails if target has no default constructor

    Hello,

    Is it true that the target object of a mixin has to have a default constructor? I'm using cglib 2.1_2 and spring 1.2.1. I've got following code to create a mixin:

    Code:
                Exception e = ...
                String stackTrace = ...
                ProxyFactory factory = new ProxyFactory();
                factory.setProxyTargetClass(true); // Enforce CGLIB usage
                factory.setTarget(e); // Exception which has to be wrapped
    
                MockControl stControl 
                    = MockControl.createControl(ServerSideStackTrace.class);
                ServerSideStackTrace st 
                    = (ServerSideStackTrace) stControl.getMock();
                st.getServiceSideStackTrace();
                stControl.setReturnValue(stackTrace, 0, Integer.MAX_VALUE);
                stControl.replay();
    
                factory.addAdvisor(0, new DefaultIntroductionAdvisor(
                    new DelegatingIntroductionInterceptor(st), 
                    ServerSideStackTrace.class));
    
                Exception wrappedException 
                    = (Exception) factory.getProxy();
                
                stControl.verify();
                return wrappedException;
    I've got the interface ServerSideStackTrace which has a method getServiceSideStackTrace to return a string. If the given exception e has a default constructor this code works. If not factory.getProxy() throws following exception:

    Code:
    java.lang.IllegalArgumentException: Superclass has no null constructors but no arguments were given
    	at net.sf.cglib.proxy.Enhancer.emitConstructors(Enhancer.java:712)
    	at net.sf.cglib.proxy.Enhancer.generateClass(Enhancer.java:499)
    	at net.sf.cglib.transform.TransformingClassGenerator.generateClass(TransformingClassGenerator.java:33)
    	at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
    	at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:215)
    	at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer.java:377)
    	at net.sf.cglib.proxy.Enhancer.create(Enhancer.java:285)
    	at org.springframework.aop.framework.Cglib2AopProxy.getProxy(Cglib2AopProxy.java:194)
    	at org.springframework.aop.framework.Cglib2AopProxy.getProxy(Cglib2AopProxy.java:150)
    	at org.springframework.aop.framework.ProxyFactory.getProxy(ProxyFactory.java:67)
    	at ch.elca.leaf3.services.remoting.protocol.soap.axis.faulthandling.DefaultHandler.enrichExceptionWithStackTrace(DefaultHandler.java:291)
    	at ch.elca.leaf3.services.remoting.protocol.soap.axis.faulthandling.DefaultHandler.translateToBusinessException(DefaultHandler.java:196)
    	at ch.elca.leaf3.services.remoting.protocol.soap.axis.faulthandling.SoapExceptionManager.translateToBusinessException(SoapExceptionManager.java:179)
    	at ch.elca.leaf3.services.remoting.protocol.soap.axis.faulthandling.ClientSoapInvocationHandler.findAndTranslateAxisFault(ClientSoapInvocationHandler.java:96)
    	at ch.elca.leaf3.services.remoting.protocol.soap.axis.faulthandling.ClientSoapInvocationHandler.findAndTranslateAxisFault(ClientSoapInvocationHandler.java:98)
    	at ch.elca.leaf3.services.remoting.protocol.soap.axis.faulthandling.ClientSoapInvocationHandler.invoke(ClientSoapInvocationHandler.java:75)
    	at $Proxy2.throwMeASpecialException(Unknown Source)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at java.lang.reflect.Method.invoke(Method.java:324)
    	at ch.elca.leaf3.services.remoting.ClientContextInvocationHandler.invoke(ClientContextInvocationHandler.java:126)
    	at $Proxy3.throwMeASpecialException(Unknown Source)
    	at ch.elca.leaf3.tests.remoting.CalculatorSoapTest.testSpecialExceptionBehaviour(CalculatorSoapTest.java:93)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at java.lang.reflect.Method.invoke(Method.java:324)
    	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:436)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:311)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
    Does anybody see what I'm doing wrong?
    Thanks for your help!

    Cheers,
    Martin

  2. #2
    Join Date
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,104

    Default

    I think this is a limitation of CGLIB - see this JIRA entry.

    You can try using interfaces + JDK dynamic proxy.

Similar Threads

  1. Odd behaviour when injecting TransactionTemplate
    By damon311 in forum Container
    Replies: 3
    Last Post: Jul 23rd, 2005, 11:21 AM
  2. Stack Overflow
    By rayho222 in forum Container
    Replies: 6
    Last Post: May 17th, 2005, 03:42 AM
  3. could not satisfy dependencies
    By springuser in forum Container
    Replies: 4
    Last Post: Apr 26th, 2005, 01:15 PM
  4. Replies: 1
    Last Post: Apr 25th, 2005, 07:37 PM
  5. Debug exceptions using ContextSingletonBeanFactoryLocator
    By timothygordon32 in forum Container
    Replies: 2
    Last Post: Feb 21st, 2005, 11:19 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •