Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-13328

Unable to intercept methods with mixed enum types as varargs

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Complete
    • Affects Version/s: 4.1.6
    • Fix Version/s: 4.2.3
    • Component/s: Core:AOP
    • Labels:
      None
    • Last commented by a User:
      false

      Description

      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:

      public <V extends IMessage> void getMessageValue(V... messages)

      And the arguments passed into this method are actually enums declared like below:

      public enum CustomMessage implements IMessage {
          WELCOME("Hello"),
          GOODBYE("Bye");
          ...
       
      }

      The method call of getMessageValue() is like:

      getMessageValue(CustomMessage.WELCOME, CustomMessage.GOODBYE);

      And there will be an exception thrown:

      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)

        Issue Links

          Activity

          Hide
          ghtrke hui gao added a comment -

          The Spring version I used in this issue is 4.1.6.RELEASE. The AspectJ version is 1.8.6.

          Show
          ghtrke hui gao added a comment - The Spring version I used in this issue is 4.1.6.RELEASE. The AspectJ version is 1.8.6.
          Hide
          juergen.hoeller Juergen Hoeller added a comment - - edited

          hui gao, I've tried several ways to reproduce this, and it always works for me. Please try to isolate a test case that actually fails for you and submit it here... ideally against 4.2.1.

          Juergen

          Show
          juergen.hoeller Juergen Hoeller added a comment - - edited hui gao , I've tried several ways to reproduce this, and it always works for me. Please try to isolate a test case that actually fails for you and submit it here... ideally against 4.2.1. Juergen
          Hide
          ghtrke hui gao added a comment -

          Sorry I forgot to mention that you have to define at least 2 child enums to pass into the method to reproduce this problem. For example:
          public enum CustomMessage implements IMessage

          { WELCOME("Hello"), GOODBYE("Bye"); ... }

          public enum CustomLabel implements IMessage

          { LANGUAGE("Language"); ... }

          The method call shall be like
          getMessageValue(CustomMessage.WELCOME, CustomLabel.LANGUAGE);

          Show
          ghtrke hui gao added a comment - Sorry I forgot to mention that you have to define at least 2 child enums to pass into the method to reproduce this problem. For example: public enum CustomMessage implements IMessage { WELCOME("Hello"), GOODBYE("Bye"); ... } public enum CustomLabel implements IMessage { LANGUAGE("Language"); ... } The method call shall be like getMessageValue(CustomMessage.WELCOME, CustomLabel.LANGUAGE);
          Hide
          juergen.hoeller Juergen Hoeller added a comment -

          This turns out to be a fairly involved change, so I'm only fixing it for 4.2.3.

          The Java compiler seems to turn the given vararg array into an Enum array in case of mixed enum arguments, not actually assignable to the target array declared with an interface type. We're explicitly detecting that case now, auto-converting the argument array if necessary.

          Juergen

          Show
          juergen.hoeller Juergen Hoeller added a comment - This turns out to be a fairly involved change, so I'm only fixing it for 4.2.3. The Java compiler seems to turn the given vararg array into an Enum array in case of mixed enum arguments, not actually assignable to the target array declared with an interface type. We're explicitly detecting that case now, auto-converting the argument array if necessary. Juergen

            People

            • Assignee:
              juergen.hoeller Juergen Hoeller
              Reporter:
              aclement Andy Clement
              Last updater:
              Juergen Hoeller
            • Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                2 years, 17 weeks, 5 days ago