-
Notifications
You must be signed in to change notification settings - Fork 38.6k
Description
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
quaff commentedon Aug 24, 2021
@F43nd1r FYI, I may be same as #27119
F43nd1r commentedon Aug 27, 2021
@quaff sounds similar and might have the same root cause. I don't have the deep understanding to say for sure.
Trympyrym commentedon Jan 19, 2023
Investigated this a bit.
@Around("exrp && !target(another_expr)")
correctly intercepts beans matchingexpr
and not matchinganother_expr
But when one of
GenericFilterBean
subclass matchesexpr
(for exampleOrderedRequestContextFilter
), then this bean is wrapped inSpringCBLIB
(OrderedRequestContextFilter$$SpringCBLIB
), and itslogger
field is not initialized, which leads to NPEtested on 6.0.3