Auto-adapt reflective arguments in case of vararg array type mismatch

Issue: SPR-13328
This commit is contained in:
Juergen Hoeller
2015-10-26 22:43:37 +01:00
parent 1c382be00e
commit 8c4b8d253a
8 changed files with 136 additions and 29 deletions

View File

@@ -19,18 +19,15 @@ package org.springframework.aop.aspectj.annotation;
import java.util.Arrays;
import org.apache.commons.logging.LogFactory;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.junit.Ignore;
import org.junit.Test;
import test.aop.PerThisAspect;
import org.springframework.util.SerializationTestUtils;
import test.aop.PerThisAspect;
import static org.junit.Assert.*;
/**
@@ -109,18 +106,27 @@ public class AspectProxyFactoryTests {
}
@Test // SPR-13328
public void testVarargsWithEnumArray() throws Exception {
public void testProxiedVarargsWithEnumArray() throws Exception {
AspectJProxyFactory proxyFactory = new AspectJProxyFactory(new TestBean());
proxyFactory.addAspect(LoggingAspect.class);
proxyFactory.setProxyTargetClass(true);
TestBean proxy = proxyFactory.getProxy();
assertTrue(proxy.doWithVarargs(MyEnum.A, MyEnum.B));
proxyFactory.addAspect(LoggingAspectOnVarargs.class);
ITestBean proxy = proxyFactory.getProxy();
assertTrue(proxy.doWithVarargs(MyEnum.A, MyOtherEnum.C));
}
@Test // SPR-13328
public void testUnproxiedVarargsWithEnumArray() throws Exception {
AspectJProxyFactory proxyFactory = new AspectJProxyFactory(new TestBean());
proxyFactory.addAspect(LoggingAspectOnSetter.class);
ITestBean proxy = proxyFactory.getProxy();
assertTrue(proxy.doWithVarargs(MyEnum.A, MyOtherEnum.C));
}
public interface ITestBean {
int getAge();
<V extends MyInterface> boolean doWithVarargs(V... args);
}
@@ -138,6 +144,7 @@ public class AspectProxyFactoryTests {
}
@SuppressWarnings("unchecked")
@Override
public <V extends MyInterface> boolean doWithVarargs(V... args) {
return true;
}
@@ -154,12 +161,29 @@ public class AspectProxyFactoryTests {
}
public enum MyOtherEnum implements MyInterface {
C, D;
}
@Aspect
public static class LoggingAspect {
public static class LoggingAspectOnVarargs {
@Around("execution(* doWithVarargs(*))")
public Object doLog(ProceedingJoinPoint pjp) throws Throwable {
LogFactory.getLog(LoggingAspect.class).debug(Arrays.asList(pjp.getArgs()));
LogFactory.getLog(LoggingAspectOnVarargs.class).debug(Arrays.asList(pjp.getArgs()));
return pjp.proceed();
}
}
@Aspect
public static class LoggingAspectOnSetter {
@Around("execution(* setAge(*))")
public Object doLog(ProceedingJoinPoint pjp) throws Throwable {
LogFactory.getLog(LoggingAspectOnSetter.class).debug(Arrays.asList(pjp.getArgs()));
return pjp.proceed();
}
}