spring-framework: Spring AOP randomly fails when advising JpaRepository
I am trying to intercept JpaRepository methods in my app, but for whatever reason, if I restart my Spring Boot app several times, then one of the aspects doesn’t always work.
The advice onBusinessRelationshipSaveAll sporadically fails, while onBusinessRelationshipDeleteAll seems to be always working.
I’ve pushed a simplified version of my app here https://github.com/gkgeorgiev/aop-demo.
Be aware that you might have to restart the app 3-4 times since the behavior is unpredictable.
I’ve also debugged and tried to understand the proxy creation, and I noticed that sometimes in the list of advisors, the pointcut advisor with expression execution(* com.example.demo.BusinessRelationshipRepository.save*(..)) is missing for whatever reason.
I initially created Stackoverflow question but the more I debugged the more I think there’s a problem with the Spring aspects mechanism.
P.S. If you are using IntelliJ … I’ve created requests.http inside the test folder, to test/reproduce the problem.
C:\dev\git\aop-demo>java -version
openjdk version "11.0.12" 2021-07-20
OpenJDK Runtime Environment Temurin-11.0.12+7 (build 11.0.12+7)
OpenJDK 64-Bit Server VM Temurin-11.0.12+7 (build 11.0.12+7, mixed mode)
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 1
- Comments: 18 (12 by maintainers)
Commits related to this issue
- Experimental fix for spring-projects/spring-framework#27761 Locally, it seems to fix the problem in the sample project. But does it make any existing tests fail? Signed-off-by: Alexander Kriegisch <... — committed to eclipse-aspectj/aspectj by kriegaex 3 years ago
- Regression test for Spring issue 27761 Relates to spring-projects/spring-framework#27761. The test needs an ASM-generated class file with reordered methods in order to reproduce the issue in plain A... — committed to eclipse-aspectj/aspectj by kriegaex 3 years ago
- Fix Spring issue 27761 Fixes spring-projects/spring-framework#27761. Fixes #256. Bridge methods are now ignored in favour of their overriding namesakes during method matching. Signed-off-by: Alexan... — committed to eclipse-aspectj/aspectj by kriegaex 3 years ago
- Regression test for Spring issue 27761 Relates to spring-projects/spring-framework#27761. The test needs an ASM-generated class file with reordered methods in order to reproduce the issue in plain A... — committed to eclipse-aspectj/aspectj by kriegaex 3 years ago
- Fix Spring issue 27761 Fixes spring-projects/spring-framework#27761. Fixes #256. Bridge methods are now ignored in favour of their overriding namesakes during method matching. Signed-off-by: Alexan... — committed to eclipse-aspectj/aspectj by kriegaex 3 years ago
I finally managed to reproduce the problem with an ASM-modified class file (but not with AspectJ on-board means). A regression test is in place, the bugfix was merged and you can re-test it with or without Spring. Please use
1.9.21-SNAPSHOT, even though I am actually considering to publish a 1.9.20.1 bugfix release, because 1.9.20 was just released last week and Java 21 support is not due before JDK 21 and the corresponding Eclipse Java Compiler changes have been released.@gkgeorgiev, @apdya, please both retest and provide feedback here.
I simply converted your JSON PUT request into Java code, replacing the driver application as follows, so you can just run it and set breakpoints wherever you like. It will also terminate automatically after execution:
Update: It also makes sense to add an unconditional log output at the beginning of each aspect advice method and also do a null check for the
relationships*collections in order to avoid ugly exceptions:Update 2: I created PR https://github.com/gkgeorgiev/aop-demo/pull/1 for everyone’s convenience. I hope it will speed up triage.