Our system has a number of security checking @Aspect aspects and we have recently switched over from using the AspectJ weaver to Spring AOP but unfortunately it appears that the Spring AOP does not implement the full point cut model from AspectJ and these aspects are now failing to function correctly.
These problem aspects all have pointcuts that include return parameters with generic types (namely collections) and what appears to be happening is Spring AOP ignores the generic type parameters causing the pointcut to match a much wider set of join points.
So given this code:
AspectJ will apply the foosChecker aspect only to the getSomeFoos method and the barsChecker aspect to the getSomeBars method.Code:@Aspect public class TheAspect { @Pointcut("execution(public !void * .*(..))") public void readPointcut() { } @AfterReturning(pointcut = "readPointcut()", returning = "foos") public void foosChecker(JoinPoint jp, Collection<Foo> foos) { ... } @AfterReturning(pointcut = "readPointcut()", returning = "bars") public void barsChecker(JoinPoint jp, Collection<Bar> bars) { ... } } public class TheAdvisedClass { public List<Foo> getSomeFoos() { ... } public List<Bar> getSomeBars() { ... } }
Spring AOP on the other hand ignores the generic type and applies the foosChecker and barsChecker aspects to both methods which results in class cast exceptions a plenty.
I did a quick search though Jira and could only find SPR-3556 which may be related.
What are the possible work arounds for this? Obviously I can creating a single uber collection aspect that then delegates to the correct sub-aspects once it's worked out the collection element type but this is a hack I'd rather avoid.
Thanks,
Oliver


Reply With Quote