Skip to content

AspectJ execution pointcut does not detect methods in superinterface anymore [SPR-16723] #21264

Closed

Description

@spring-projects-issues

Tiberiu Tofan opened SPR-16723 and commented

After upgrading from Spring Boot 2.0.0.M7 (Sprig AOP 5.0.2) to Spring Boot 2.0.1.RELEASE (Spring AOP 5.0.5) the following advice doesn't work anymore:

@Around("execution(* org.springframework.data.mongodb.repository.MongoRepository.deleteById(..)) && args(id)")

It looks like the pointcut ignores methods that are declared only in a super interface. If I actually override the methods in my MongoRepository, the advice is applied.

A workaround for this is to use the interface where the method is actually declared as a execution pointcut, and specify the target separately:

@Around("target(org.springframework.data.mongodb.repository.MongoRepository) && execution(* org.springframework.data.repository.CrudRepository.deleteById(*)) && args(id)")

Affects: 5.0.5

Issue Links:

Activity

  1. spring-projects-issues commented on Apr 13, 2018

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    This turns out to be a side effect of 5.0.5's changes for more efficient proxy treatment: #21216 and more specifically for this issue here #21218. AspectJ is unable to evaluate pointcuts that refer to methods against an interface with the method actually declared on a superinterface... but previously we nevertheless detected them on the concrete class that we were also checking, and that AspectJ introspects fine even for such interface-declared methods. This is still the case for regular classes but not for dynamic interface proxies where we thought we could skip the generated proxy class since it won't reveal any more methods than the interfaces do already... It seems we'll have to re-add that defensive check against the proxy class, even if effectively just needed for AspectJ pointcuts.

    So overall, this is quite specific to Spring Data with its runtime-generated interface proxies with a multi-level inheritance hierarchy. I've got a working fix for master and will backport it to 5.0.x ASAP, for release in 5.0.6 in about two weeks (to be picked by Boot 2.0.2 right away).

  2. spring-projects-issues commented on Apr 14, 2018

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    While this regression is rather specific to Spring Data, there is a generally issue uncovered through it: AspectJ pointcut evaluation doesn't understand such subinterface references to methods on superinterfaces if they are not redeclared further down the hierarchy (e.g. on a subinterface or on the concrete class). This involves dynamic proxies with interface inheritance (like in the case above which worked in older versions as a side effect) but also Java 8 default methods on interfaces for regular bean classes (which never worked with such pointcuts).

    For 5.0.6, I'm trying to address the underlying issue rather than reverting the optimization that caused the immediate regression in 5.0.5.

  3. spring-projects-issues commented on Apr 14, 2018

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    I've pushed my revision for 5.1 and 5.0.6. Please give an upcoming 5.1.0.BUILD-SNAPSHOT or 5.0.6.BUILD-SNAPSHOT a try and let me know whether it works for you...

  4. added
    type: regression
    in: core
    on Jan 11, 2019
  5. added this to the 5.0.6 milestone on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: coretype: regression

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions