Skip to content

AOP !target not negating target pointcut expression #27302

@F43nd1r

Description

@F43nd1r

Affects: At least 4.2.1 - 5.3.9, probably all versions.


A !target(class) pointcut doesn't behave as expected: It seems like the negation implementation is wrong.

From my testing x && !target(org.springframework.web.filter.GenericFilterBean) behaves like x || target(org.springframework.web.filter.GenericFilterBean) instead.

I've created an example project https://github.com/F43nd1r/spring-aop-negation-issue-demo. Just try to run the application. You'll see a stacktrace like this:

java.lang.NullPointerException: Cannot invoke "org.apache.commons.logging.Log.isDebugEnabled()" because "this.logger" is null
	at org.springframework.web.filter.GenericFilterBean.init(GenericFilterBean.java:241)

That means a bean extending GenericFilterBean must've matched the pointcut and thus was proxied (GenericFilterBean implementations cannot be cglib proxied due to its implementation).

Note: This issue was also described in this stackoverflow post nearly six years ago https://stackoverflow.com/questions/33136530/target-negation-not-working-in-spring-aop.

Activity

added
in: coreIssues in core modules (aop, beans, core, context, expression)
on Aug 20, 2021
quaff

quaff commented on Aug 24, 2021

@quaff
Contributor

@F43nd1r FYI, I may be same as #27119

F43nd1r

F43nd1r commented on Aug 27, 2021

@F43nd1r
Author

@quaff sounds similar and might have the same root cause. I don't have the deep understanding to say for sure.

added this to the Triage Queue milestone on Jan 3, 2022
self-assigned this
on Jan 4, 2022
added and removed on Jan 18, 2022
Trympyrym

Trympyrym commented on Jan 19, 2023

@Trympyrym
Contributor

Investigated this a bit.

@Around("exrp && !target(another_expr)") correctly intercepts beans matching expr and not matching another_expr

But when one of GenericFilterBean subclass matches expr (for example OrderedRequestContextFilter), then this bean is wrapped in SpringCBLIB (OrderedRequestContextFilter$$SpringCBLIB), and its logger field is not initialized, which leads to NPE

tested on 6.0.3

removed their assignment
on Dec 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: coreIssues in core modules (aop, beans, core, context, expression)type: bugA general bug

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @sbrannen@quaff@jhoeller@F43nd1r@spring-projects-issues

        Issue actions

          AOP !target not negating target pointcut expression · Issue #27302 · spring-projects/spring-framework