question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AspectJ proxy bean gives IllegalAccessException in Java 16

See original GitHub issue

Here is a sample project which demonstrates the issue with SB 2.4 and JDK 16 https://github.com/EvgeniGordeev/spring-boot-java-16-aspectj-proxy-error.

The application cannot start due to:

Caused by: java.lang.IllegalAccessException: module java.base does not open java.lang to unnamed module @11dc3715
	at java.base/java.lang.invoke.MethodHandles.privateLookupIn(MethodHandles.java:260) ~[na:na]
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78) ~[na:na]
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
	at java.base/java.lang.reflect.Method.invoke(Method.java:567) ~[na:na]
	at org.springframework.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:574) ~[spring-core-5.3.6.jar:5.3.6]
	... 23 common frames omitted

Valid for beans with @Transactional and when SpringBootApplication combines @EnableAspectJAutoProxy and @EnableTransactionManagement.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
philwebbcommented, May 15, 2021

I’m going to transfer this one to the Spring Framework team for assessment. Spring Boot isn’t actually involved in the proxy creation, it’s a framework concern. This looks similar to https://github.com/spring-projects/spring-framework/issues/26440 but there’s no module-info involved in your sample.

0reactions
wilkinsonacommented, May 18, 2021

I’m not sure how we can fix this one either. In this case contextClass is java.lang.Object so getClassLoader() returns null. The loader argument is the app class loader (jdk.internal.loader.ClassLoaders$AppClassLoader).

As far as I can tell, the failure is specific to proxying of methods defined in the JDK such as Object#toString which is the method being called in the sample. Calling testMethod() on the proxied service doesn’t trigger the problem and works fine (once the sample’s dependencies have been updated a little so that a transaction manager is auto-configured).

Read more comments on GitHub >

github_iconTop Results From Across the Web

AspectJ proxy bean gives IllegalAccessException in Java 16
@philwebb It looks like this is yet another case of a ClassLoader mismatch on proxy creation. This warning/exception will appear any time the ......
Read more >
How to invoke spring bean method with all proxies/aspects?
Java : 11, Spring-boot: 2.5.3. I am trying to implement some annotation-based abstraction on event processing. I have created annotation ...
Read more >
IllegalAccessException (Java SE 16 & JDK 16)
An IllegalAccessException is thrown when an application tries to reflectively create an instance (other than an array), set or get a field, ...
Read more >
Spring JDK Proxies vs CGLIB vs AspectJ - Credera
It demonstrates that if you're using a JDK proxy and the join point annotation is present on the concrete implementation of a bean...
Read more >
Before i use @Mapper(IntegerMapper.class) but now is ...
java.lang.IllegalArgumentException: A bean, int, was mapped which was not instantiable ... invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:621).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found