Results 1 to 3 of 3

Thread: Issue switching from AspectJ to Spring AOP

  1. #1
    Join Date
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    335

    Default 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:

    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() { ... }
    }
    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.

    Thanks,

    Oliver

  2. #2
    Join Date
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    335

    Default

    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. #3
    Join Date
    Aug 2004
    Posts
    2,715

    Default

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •