Skip to content

Unable to intercept methods with mixed enum types as varargs [SPR-13328] #17913

@spring-projects-issues

Description

@spring-projects-issues

Andy Clement opened SPR-13328 and commented

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)

Affects: 4.1.6

Issue Links:

Referenced from: commits 8c4b8d2, a8432bc

0 votes, 5 watchers

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions