MethodHandles.Lookup.defineClass for CGLIB class definition purposes [SPR-15859]
See original GitHub issueJuergen Hoeller opened SPR-15859 and commented
As discussed in https://github.com/cglib/cglib/commit/d6fe1d8c73508ef30883eb1f9ae965d15953e7d0 and in #20245 comments, there is currently a defineClass
warning triggered by CGLIB when running on JDK 9 in classpath mode. While there are workarounds for it (“illegal-access=deny” or “add-opens java.base/java.lang=ALL-UNNAMED”), suppressing that warning at runtime, it’d be nice to avoid the warning completely when running on JDK 9, possibly through a specific check for JDK 9 which skips the ClassLoader.defineClass
access attempt completely, always going with the Unsafe.defineClass
fallback right away in such a scenario. We have yet to see whether this can be patched in CGLIB itself or just in Spring’s CGLIB fork.
UPDATE: Since JDK 11 won’t have Unsafe.defineClass
at all anymore, we need to use MethodHandles.Lookup.defineClass
as our primary mechanism, avoiding a ClassLoader.defineClass
warning on the classpath and providing compatibility with the module path on JDK 11.
Affects: 5.0 RC3
Reference URL: https://github.com/cglib/cglib/commit/d6fe1d8c73508ef30883eb1f9ae965d15953e7d0
Issue Links:
- #20937 Compatibility with JDK 11 (“is depended on by”)
- #21317 An illegal reflective access operation has occurred (“duplicates”)
- #20493 Running an app with
@Configuration
using Java 9 prints ugly illegal access warnings (“is duplicated by”) - #20783 ReflectUtils produces Warning in Spring Boot 2.0.0.M6 and Java 9.0.1 (“is duplicated by”)
- #19713 Upgrade to CGLIB 3.2.5
- DATACMNS-1376 Assure JDK 11 compatibility for DefaultMethodInvokingMethodInterceptor
- #21913 i’m new with spring and from the start i found this warning while executing
- #21441 Spring Boot DevTools on 5.1 fails with java.lang.LinkageError: loader attempted duplicate class definition
- #22032 Illegal reflective access operation warning for toString() on CGLIB proxies
- DATACMNS-1401 Warning about illegal reflective access in Spring Data Commons / MongoDB
Referenced from: commits https://github.com/spring-projects/spring-framework/commit/6a34ca24ceb031d45fb9f6ce4847eaeb82774901, https://github.com/spring-projects/spring-framework/commit/61c3db0869416bf61e7e4cbc5bd7dd2ece24b0a2
17 votes, 40 watchers
Issue Analytics
- State:
- Created 6 years ago
- Comments:39 (1 by maintainers)
I hope this is the right place to add my comment even if the issue is closed. I have the same thing on Java 11 with Spring 5.2.3
WARNING: Illegal reflective access by org.springframework.cglib.core.ReflectUtils (vfs:/D:/wildfly-18.0.1/servers/abc-j11/deployments/abc.war/WEB-INF/lib/spring-core-5.2.3.RELEASE.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) at deployment.abc.war//org.springframework.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:525) at deployment.abc.war//org.springframework.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:363) at deployment.abc.war//org.springframework.cglib.proxy.Enhancer.generate(Enhancer.java:582) at deployment.abc.war//org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:110) at deployment.abc.war//org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:108) at deployment.abc.war//org.springframework.cglib.core.internal.LoadingCache$2.call(LoadingCache.java:54) at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) at deployment.abc.war//org.springframework.cglib.core.internal.LoadingCache.createEntry(LoadingCache.java:61) at deployment.abc.war//org.springframework.cglib.core.internal.LoadingCache.get(LoadingCache.java:34) at deployment.abc.war//org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData.get(AbstractClassGenerator.java:134) at deployment.abc.war//org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:319) at deployment.abc.war//org.springframework.cglib.proxy.Enhancer.createHelper(Enhancer.java:569) at deployment.abc.war//org.springframework.cglib.proxy.Enhancer.create(Enhancer.java:384)
What can I do about it?
I am seeing this on spring boot 2.1.6.RELEASE as well in a JDK11 environment