spring-projects / spring-projects/spring-framework

AOP !target not negating target pointcut expression

Open
#27,302 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

in: core type: bug
Dominant language
Java
Stars
60.2k
Forks
38.8k
Avg merge
5d 2h
Merged PRs (30d)
27

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked spring-aop-negation-issue-demo and run the application to reproduce the stacktrace at GenericFilterBean.java:241. Trace how the AOP pointcut combines x && !target(org.springframework.web.filter.GenericFilterBean); done means the negated target expression excludes GenericFilterBean implementations and the reported failure no longer occurs.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.