java.lang.ClassCastException: Sample cannot be cast to Sample

Spring JIRA | Dave Syer | 5 months ago
tip
Click on the to mark the solution that helps you, Samebug will learn from it.
As a community member, you’ll be rewarded for you help.
  1. 0

    A groovy bean defined through `<lang:groovy/>` is supposed to be refreshable (and there are tests that prove it I know). But actually executing a method on one of those beans after a refresh appears to be an error: {noformat} 2016-09-15 11:46:50.517 ERROR 22523 --- [nio-8080-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet]  : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.ClassCastException: Sample cannot be cast to Sample] with root cause java.lang.ClassCastException: Sample cannot be cast to Sample at Sample$$FastClassBySpringCGLIB$$932c61ca.invoke(<generated>) ~[na:na] at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) ~[spring-core-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:720) ~[spring-aop-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) ~[spring-aop-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133) ~[spring-aop-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121) ~[spring-aop-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:655) ~[spring-aop-4.3.2.RELEASE.jar:4.3.2.RELEASE] at Sample$$EnhancerBySpringCGLIB$$e2736740.home(<generated>) ~[na:na] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_60] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_60] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_60] at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_60] at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221) ~[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE] ... {noformat} Here's a sample: https://github.com/spring-projects/spring-framework-issues/pull/140 (just run the app, curl the home page, then edit the script and try again). It's a Spring Cloud user again that noticed this: https://github.com/spring-cloud/spring-cloud-netflix/issues/223

    Spring JIRA | 5 months ago | Dave Syer
    java.lang.ClassCastException: Sample cannot be cast to Sample

    Root Cause Analysis

    1. java.lang.ClassCastException

      Sample cannot be cast to Sample

      at Sample$$FastClassBySpringCGLIB$$932c61ca.invoke()
    2. Unknown
      Sample$$FastClassBySpringCGLIB$$932c61ca.invoke
      1. Sample$$FastClassBySpringCGLIB$$932c61ca.invoke(<generated>)[na:na]
      1 frame
    3. Spring Core
      MethodProxy.invoke
      1. org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)[spring-core-4.3.2.RELEASE.jar:4.3.2.RELEASE]
      1 frame
    4. Spring AOP
      CglibAopProxy$DynamicAdvisedInterceptor.intercept
      1. org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:720)[spring-aop-4.3.2.RELEASE.jar:4.3.2.RELEASE]
      2. org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)[spring-aop-4.3.2.RELEASE.jar:4.3.2.RELEASE]
      3. org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133)[spring-aop-4.3.2.RELEASE.jar:4.3.2.RELEASE]
      4. org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121)[spring-aop-4.3.2.RELEASE.jar:4.3.2.RELEASE]
      5. org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)[spring-aop-4.3.2.RELEASE.jar:4.3.2.RELEASE]
      6. org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:655)[spring-aop-4.3.2.RELEASE.jar:4.3.2.RELEASE]
      6 frames
    5. Unknown
      Sample$$EnhancerBySpringCGLIB$$e2736740.home
      1. Sample$$EnhancerBySpringCGLIB$$e2736740.home(<generated>)[na:na]
      1 frame
    6. Java RT
      Method.invoke
      1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)[na:1.8.0_60]
      2. sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)[na:1.8.0_60]
      3. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)[na:1.8.0_60]
      4. java.lang.reflect.Method.invoke(Method.java:497)[na:1.8.0_60]
      4 frames
    7. Spring
      InvocableHandlerMethod.doInvoke
      1. org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE]
      1 frame