Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AOP !target not negating target pointcut expression #27302

Open
F43nd1r opened this issue Aug 20, 2021 · 3 comments
Open

AOP !target not negating target pointcut expression #27302

F43nd1r opened this issue Aug 20, 2021 · 3 comments
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug

Comments

@F43nd1r
Copy link

F43nd1r commented Aug 20, 2021

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.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Aug 20, 2021
@sbrannen sbrannen added the in: core Issues in core modules (aop, beans, core, context, expression) label Aug 20, 2021
@quaff
Copy link
Contributor

quaff commented Aug 24, 2021

@F43nd1r FYI, I may be same as #27119

@F43nd1r
Copy link
Author

F43nd1r commented Aug 27, 2021

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

@sbrannen sbrannen added this to the Triage Queue milestone Jan 3, 2022
@jhoeller jhoeller self-assigned this Jan 4, 2022
@jhoeller jhoeller added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jan 18, 2022
@Trympyrym
Copy link
Contributor

Trympyrym commented Jan 19, 2023

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

@jhoeller jhoeller removed their assignment Dec 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

6 participants