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.

MethodHandles.Lookup.defineClass for CGLIB class definition purposes [SPR-15859]

See original GitHub issue

Juergen 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:closed
  • Created 6 years ago
  • Comments:39 (1 by maintainers)

github_iconTop GitHub Comments

14reactions
azmaucommented, Feb 14, 2020

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?

10reactions
peterhuffercommented, Jul 11, 2019

I am seeing this on spring boot 2.1.6.RELEASE as well in a JDK11 environment

WARNING: An illegal reflective access operation has occurred

WARNING: Illegal reflective access by org.springframework.util.ReflectionUtils (jar:file:/opt/replication/app.jar!/BOOT-INF/lib/spring-core-5.1.8.RELEASE.jar!/) to field java.beans.PropertyChangeSupport.map

WARNING: Please consider reporting this to the maintainers of org.springframework.util.ReflectionUtils

WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
Read more comments on GitHub >

github_iconTop Results From Across the Web

SPR-15859 - Spring JIRA
No information is available for this page.
Read more >
MethodHandles.Lookup (Java SE 9 & JDK 9 )
A shared Lookup object delegates the capability to create method handles on private members of the lookup class. Even if privileged code uses...
Read more >
Set Jvm Option For Avoid Error Illegal Reflective Access By ...
Improvement An improvement or enhancement to an existing feature or task. SPR15859 MethodHandles.Lookup.defineClass for CGLIB class definition.
Read more >
Spring 5.0.5 在jdk9 环境下启动警告_weixin_34054866的博客
见Spring Framework/SPR-15859: MethodHandles.Lookup.defineClass for CGLIB class definition purposes.
Read more >
spring-projects/spring-framework v5.1.0.RC1 on GitHub
setBearerAuth(String) [SPR-16997] #21535; Support platforms where Class is not ... Lookup.defineClass for CGLIB class definition purposes [SPR-15859] #20414 ...
Read more >

github_iconTop Related Medium Post

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