java.lang.ClassCastException: [Ljava.lang.Enum; cannot be cast to [Lcom.read.maventest.interface.IMessage;

Spring JIRA | Andy Clement | 2 years 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

    This was raised against AspectJ but I'm thinking (from the stack trace) it may be Spring AOP. The AJ bug is : https://bugs.eclipse.org/bugs/show_bug.cgi?id=474266 and the text from that is: The method I used AspectJ+SpringAOP to intercept is declared as below: {code}public <V extends IMessage> void getMessageValue(V... messages){code} And the arguments passed into this method are actually enums declared like below: {code}public enum CustomMessage implements IMessage { WELCOME("Hello"), GOODBYE("Bye"); ... }{code} The method call of getMessageValue() is like: {code}getMessageValue(CustomMessage.WELCOME, CustomMessage.GOODBYE);{code} And there will be an exception thrown: {code}java.lang.ClassCastException: [Ljava.lang.Enum; cannot be cast to [Lcom.read.maventest.interface.IMessage; at com.read.maventest.bean.TestEnumList$$FastClassBySpringCGLIB$$21d778f3.invoke(<generated>) at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:717) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:52) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:85) at com.read.maventest.bean.TimingAspect.timeStats(TimingAspect.java:25) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497){code}

    Spring JIRA | 2 years ago | Andy Clement
    java.lang.ClassCastException: [Ljava.lang.Enum; cannot be cast to [Lcom.read.maventest.interface.IMessage;
  2. 0

    This was raised against AspectJ but I'm thinking (from the stack trace) it may be Spring AOP. The AJ bug is : https://bugs.eclipse.org/bugs/show_bug.cgi?id=474266 and the text from that is: The method I used AspectJ+SpringAOP to intercept is declared as below: {code}public <V extends IMessage> void getMessageValue(V... messages){code} And the arguments passed into this method are actually enums declared like below: {code}public enum CustomMessage implements IMessage { WELCOME("Hello"), GOODBYE("Bye"); ... }{code} The method call of getMessageValue() is like: {code}getMessageValue(CustomMessage.WELCOME, CustomMessage.GOODBYE);{code} And there will be an exception thrown: {code}java.lang.ClassCastException: [Ljava.lang.Enum; cannot be cast to [Lcom.read.maventest.interface.IMessage; at com.read.maventest.bean.TestEnumList$$FastClassBySpringCGLIB$$21d778f3.invoke(<generated>) at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:717) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:52) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:85) at com.read.maventest.bean.TimingAspect.timeStats(TimingAspect.java:25) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497){code}

    Spring JIRA | 2 years ago | Andy Clement
    java.lang.ClassCastException: [Ljava.lang.Enum; cannot be cast to [Lcom.read.maventest.interface.IMessage;

    Root Cause Analysis

    1. java.lang.ClassCastException

      [Ljava.lang.Enum; cannot be cast to [Lcom.read.maventest.interface.IMessage;

      at com.read.maventest.bean.TestEnumList$$FastClassBySpringCGLIB$$21d778f3.invoke()
    2. com.read.maventest
      TestEnumList$$FastClassBySpringCGLIB$$21d778f3.invoke
      1. com.read.maventest.bean.TestEnumList$$FastClassBySpringCGLIB$$21d778f3.invoke(<generated>)
      1 frame
    3. Spring Core
      MethodProxy.invoke
      1. org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
      1 frame
    4. Spring AOP
      MethodInvocationProceedingJoinPoint.proceed
      1. org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:717)
      2. org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
      3. org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:52)
      4. org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
      5. org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:85)
      5 frames
    5. com.read.maventest
      TimingAspect.timeStats
      1. com.read.maventest.bean.TimingAspect.timeStats(TimingAspect.java:25)
      1 frame
    6. Java RT
      DelegatingMethodAccessorImpl.invoke
      1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      2. sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      3. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      3 frames