- 
                Notifications
    You must be signed in to change notification settings 
- Fork 38.8k
Closed
Labels
in: coreIssues in core modules (aop, beans, core, context, expression)Issues in core modules (aop, beans, core, context, expression)type: regressionA bug that is also a regressionA bug that is also a regression
Milestone
Description
Yanming Zhou opened SPR-16803 and commented
If target object is JDK dynamic proxy, Aspectj annotation pointcut match failed since proxy class method lost annotations, here is a simple test
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import java.lang.reflect.Method;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.junit.Test;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.support.AopUtils;
import org.springframework.transaction.annotation.Transactional;
public class AopUtilsTest {
	@Test
	public void getMostSpecificMethod() throws Exception {
		MyInterface proxy = (MyInterface) new ProxyFactory(MyInterface.class, new MyMethodInterceptor())
				.getProxy(MyInterface.class.getClassLoader());
		Method interfaceMethod = MyInterface.class.getMethod("test");
		Method proxyMethod = proxy.getClass().getMethod("test");
		Method mostSpecificMethod = AopUtils.getMostSpecificMethod(interfaceMethod, proxy.getClass());
		assertNotEquals(proxyMethod, interfaceMethod);
		assertEquals(interfaceMethod, mostSpecificMethod); //failed
		assertNotNull(mostSpecificMethod.getAnnotation(Transactional.class));
	}
	public static interface MyInterface {
		@Transactional
		public String test();
	}
	public static class MyMethodInterceptor implements MethodInterceptor {
		@Override
		public Object invoke(MethodInvocation mi) throws Throwable {
			return null;
		}
	}
}We should add a short-circuit
if(Proxy.isProxyClass(targetClass))
     return method;I'm not sure this change should apply for AopUtils.getMostSpecificMethod() or ClassUtils.getMostSpecificMethod()
Affects: 5.0.6
Attachments:
- spr16803.zip (7.46 kB)
Issue Links:
- AspectJ execution pointcut does not detect methods in superinterface anymore [SPR-16723] #21264 AspectJ execution pointcut does not detect methods in superinterface anymore
- AopUtils.getMostSpecificMethod should expose dynamic proxy class methods [SPR-16757] #21298 AopUtils.getMostSpecificMethod should expose dynamic proxy class methods
- Mixed use BeanNameAutoProxyCreator and AnnotationAwareAspectJAutoProxyCreator to proxy same bean [SPR-16677] #21218 Mixed use BeanNameAutoProxyCreator and AnnotationAwareAspectJAutoProxyCreator to proxy same bean
- Spring 5.x DataSource proxying does not work with Oracle UCP on JDK 9+ [SPR-17003] #21541 Spring 5.x DataSource proxying does not work with Oracle UCP on JDK 9+
Metadata
Metadata
Assignees
Labels
in: coreIssues in core modules (aop, beans, core, context, expression)Issues in core modules (aop, beans, core, context, expression)type: regressionA bug that is also a regressionA bug that is also a regression