Announcement Announcement Module
No announcement yet.
Issue switching from AspectJ to Spring AOP Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Issue switching from AspectJ to Spring AOP

    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:

    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() { ... }
    AspectJ will apply the foosChecker aspect only to the getSomeFoos method and the barsChecker aspect to the getSomeBars method.

    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.



  • #2
    Since there's been no response I'm going to assume this is an unknown issue and I've raised it in Jira - SPR-3628.


    • #3
      Could this be related to the recently fixed bug SPR-3556?