-
Notifications
You must be signed in to change notification settings - Fork 38.5k
@annotation
pointcut is not matched with complex hierarchy and generics against classes compiled by Eclipse [SPR-17310]
#21843
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Yanming Zhou commented It seems eclipse compiler bug. I'm not sure it has relation with https://bugs.eclipse.org/bugs/show_bug.cgi?id=495396 |
Yanming Zhou commented I have reported https://bugs.eclipse.org/bugs/show_bug.cgi?id=539651 |
Yanming Zhou commented Finally I figure it out, method.getDeclaringClass() return wrong class with eclipse compiler, it cause spring ClassUtils.getMostSpecificMethod() return wrong method. @Test
public void test() throws Exception {
Class<?> targetClass = UserManagerImpl.class;
Method method = targetClass.getMethod("save", Persistable.class);
assertEquals(targetClass, method.getDeclaringClass()); // eclipse compiler fail
} |
Yanming Zhou commented javac create two bridge methods: public void com.example.UserManagerImpl.save(com.example.Persistable)
public void com.example.UserManagerImpl.save(com.example.BaseUser) ecj create only one bridge method: public void com.example.UserManagerImpl.save(com.example.BaseUser) It seems a corner case that JLS not covered, maybe it's not a bug of eclipse compiler, Juergen Hoeller could you make some changes to keep compatibility with both of them? |
Yanming Zhou commented Workaround: add two lines before return statement resolvedMethod = BridgeMethodResolver.findBridgedMethod(resolvedMethod);
resolvedMethod = ClassUtils.getMostSpecificMethod(resolvedMethod, specificTargetClass); |
Minimized unit test, It will fail in eclipse. import static org.junit.Assert.assertEquals;
import java.lang.reflect.Method;
import org.junit.Test;
import org.springframework.aop.support.AopUtils;
public class AopUtilsTest {
@Test
public void testGetMostSpecificMethod() throws Exception {
String methodName = "feed";
Class<?> targetClass = DogService.class;
Method targetMethod = targetClass.getDeclaredMethod(methodName, Dog.class);
Method originalMethod = AnimalService.class.getDeclaredMethod(methodName, Animal.class);
Method actualMethod = AopUtils.getMostSpecificMethod(originalMethod, targetClass);
assertEquals("Please ensure class compiled with javac not eclipse", targetMethod, actualMethod);
}
public static class Animal {
}
public static abstract class Mammal extends Animal {
}
public static class Dog extends Mammal {
}
public static class AnimalService<T extends Animal> {
public void feed(T obj) {
}
}
public static class MammalService<T extends Mammal> extends AnimalService<T> {
@Override
public void feed(T obj) {
}
}
public static class DogService extends MammalService<Dog> {
@Override
public void feed(Dog obj) {
}
}
} |
Courtesy of @wilkinsona, the test is still failing with the latest Spring Framework 6.1 milestone. @jhoeller wondering if we could accommodate with this difference between the eclipse and Java compiler? |
I've addressed this through a new combined |
@annotation
pointcut is not matched with complex hierarchy and generics against classes compiled by Eclipse [SPR-17310]
Yanming Zhou opened SPR-17310 and commented
The mostSpecificMethod should return method UserManagerImpl.save(User), but return BaseUserManagerImpl.save(BaseUser) which doesn't annotated, it will cause
@annotation
pointcut broken.Affects: 5.1 GA
Attachments:
The text was updated successfully, but these errors were encountered: