Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-3463

Spring/CGLIB proxies throw exception "object is not an instance of declaring class"

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.6, 1.6.1
    • 1.7.5, 1.8-beta-2
    • None
    • None
    • Windows XP, JDK 1.6

    Description

      Groovy classes wrapped by Spring (CGLIB scoped proxies) throw an exception "object is not an instance of declaring class" when accessed. This behavior does not happen with Groovy 1.5.8. I have attached a test case.

      Instructions for test case: this is a zip of an IDEA project to build a minimal Spring web app. The real action is in src/gtest/RegularBean.groovy, which invokes a scoped proxy. This zip archive is complete except for a bunch of jars I left out to keep the size down. See lib/filelist.txt for the list of jars that should be copied into that dir. To build, run "ant" in the GroovyTest dir. To build the war, run "ant j2ee.build.jar.groovytestweb".

      To reproduce, deploy the webapp and open index.html with your browser. For example:

      http://localhost:8080/groovytest/index.html

      The exception should display in the browser window. It should look like the following:

      java.lang.IllegalArgumentException: object is not an instance of declaring class
      sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      java.lang.reflect.Method.invoke(Method.java:597)
      org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
      groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
      groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:2402)
      groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:3307)
      gtest.ParentBean.setProperty(ParentBean.groovy)
      gtest.ParentBean$$FastClassByCGLIB$$6043f72f.invoke(<generated>)
      net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
      org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:696)
      org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
      org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:131)
      org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:119)
      org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
      org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:631)
      gtest.SessionScopedBean$$EnhancerByCGLIB$$d8ea54c.setProperty(<generated>)
      org.codehaus.groovy.runtime.ScriptBytecodeAdapter.setGroovyObjectProperty(ScriptBytecodeAdapter.java:530)
      gtest.RegularBean.doStuff(RegularBean.groovy:10)
      gtest.RegularBeanIf$doStuff.call(Unknown Source)
      gtest.HomePageController.handleRequestInternal(HomePageController.groovy:15)
      org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
      org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
      org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:859)
      org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:793)
      org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:476)
      org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:431)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

      Attachments

        1. GROOVY-3463.groovy
          1 kB
          Guillaume Sauthier
        2. Stacktrace.log
          4 kB
          Ari Erin Miller
        3. cglibexp.tar
          2.33 MB
          Ari Erin Miller
        4. GroovyTest.zip
          16 kB
          Christopher Wong

        Activity

          People

            guillaume Guillaume Sauthier
            cwong15 Christopher Wong
            Votes:
            13 Vote for this issue
            Watchers:
            8 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: