spring-framework: on JDK 11 - WARNING: Illegal reflective access by org.springframework.cglib.core.ReflectUtils$1 (file:/C:/Users/.../spring-core/4.3.22.RELEASE/spring-core-4.3.22.RELEASE.jar)

Error for Spring Boot 1.5.x (1.5.19.RELEASE, using the latest spring-core-4.3.22.RELEASE.jar)

I have not seen this error before within previous boot 1.5.17.RELEASE.
And frankly upgrade to the latest 1.5.19.RELEASE/spring-core-4.3.22.RELEASE.jar was maybe 1-2 weeks ago.

So why this error appeared?

14:43:23.388 [main] INFO  o.s.b.f.s.DefaultListableBeanFactory#registerBeanDefinition:826 - Overriding bean definition for bean 'managementServletContext' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.actuate.autoconfigure.EndpointWebMvcHypermediaManagementContextConfiguration; factoryMethodName=managementServletContext; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/actuate/autoconfigure/EndpointWebMvcHypermediaManagementContextConfiguration.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.actuate.autoconfigure.EndpointWebMvcAutoConfiguration; factoryMethodName=managementServletContext; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfiguration.class]]
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.springframework.cglib.core.ReflectUtils$1 (file:/C:/Users/myuserlogin/.m2/repository/org/springframework/spring-core/4.3.22.RELEASE/spring-core-4.3.22.RELEASE.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of org.springframework.cglib.core.ReflectUtils$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
14:43:25.687 [main] INFO  o.s.b.f.a.AutowiredAnnotationBeanPostProcessor#<init>:155 - JSR-330 'javax.inject.Inject' annotation found and supported for autowiring

image

ref https://github.com/spring-projects/spring-framework/issues/22019

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 7
  • Comments: 48 (14 by maintainers)

Most upvoted comments

@cy503328434 I am getting the same warning on OS Windows 10, jdk-11.0.2, Spring boot 2.2.1,spring-core/5.2.1.RELEASE!

same warning on openjdk64-11.0.2, spring-core-5.2.2.RELEASE.jar, spring boot 2.2.2.RELEASE

I’m getting the same on spring-core-5.1.10 with jdk 11. This should be reopened.

I am experiencing this warning on MacOS Catalina, oracle JDK11, spring 5.1.6 and spring boot 2.1.10 Can you please inform me of a solution (not the mentioned work around of --add jvm option as mention in stackoverflow)

OS Windows 10, jdk-11.0.5, Spring boot 2.2.1,spring-core/5.2.1.RELEASE, I noticed stille has:WARNING: An illegal reflective access operation has occurred WARNING: Illegal reflective access by org.springframework.cglib.core.ReflectUtils (file:/E:/dev/gradle/repository/caches/modules-2/files-2.1/org.springframework/spring-core/5.2.1.RELEASE/32b265ff5c7c35257b5a242b9628dcd321a2b010/spring-core-5.2.1.RELEASE.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) WARNING: Please consider reporting this to the maintainers of org.springframework.cglib.core.ReflectUtils WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations WARNING: All illegal access operations will be denied in a future release

AdoptOpenJdk 14.0.1 Spring Boot 2.3.1

WARNING: An illegal reflective access operation has occurred WARNING: Illegal reflective access by org.springframework.cglib.core.ReflectUtils (file:/C:/Users/condo/.m2/repository/org/springframework/spring-core/5.2.7.RELEASE/spring-core-5.2.7.RELEASE.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) WARNING: Please consider reporting this to the maintainers of org.springframework.cglib.core.ReflectUtils WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations WARNING: All illegal access operations will be denied in a future release

Edit | 2020-11-16: AdoptOpenJDK: 15.0.1+9 Spring Boot 2.4.0.

WARNING: An illegal reflective access operation has occurred WARNING: Illegal reflective access by org.springframework.cglib.core.ReflectUtils (file:/C:/Users/condo/.m2/repository/org/springframework/spring-core/5.3.1/spring-core-5.3.1.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) WARNING: Please consider reporting this to the maintainers of org.springframework.cglib.core.ReflectUtils WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations WARNING: All illegal access operations will be denied in a future release

Same, Mac OS Mojave . openjdk 11.0.6 2020-01-14. spring boot 2.2.4.RELEASE

@paulvi java -version is not a proof that the process you are running is using that version.

Please note that this warning can still happen on Spring Framework 5.1+ in case of certain ClassLoader scenarios and certain kinds of application classes to be proxied. The root of the problem is that there is no full replacement for the (non-public) ClassLoader.defineClass mechanism in JDK 9+ since Lookup.defineClass does not allow for specifying the ClassLoader to define the class in (it rather always uses the ClassLoader of the given context class). For that reason, we have to keep using ClassLoader.defineClass in case of custom ClassLoader architectures such as OSGi, some Java EE scenarios, and also DevTools reloading. Some occurrences of that warning are therefore totally expected; we only ´fixed´ the case that we can actually address with the replacement API.

As for the warning itself, as Stéphane mentioned, unfortunately it only indicates that Spring’s CGLIB variant has been used for creating a class in a specific ClassLoader where ClassLoader.defineClass still has to be used. What we really need to know about is the particular class that triggered the warning, the ClassLoader architecture in use, and the code path that led to the creation attempt.

For me it resolved, in Windows 10 In Intellij IDEA Community Edition 2019.2.3 follow the steps:

  • Go to the C:\Users\UserName.m2 directory and remove everything.
  • In Intellij, right click on the project, Maven > Reimport
  • Expect to load all dependencies.
  • Right click on the project, Open Module Settings > Change the SDK to 1.8.0_221.

In Eclipse IDE Jee 2019-09 follow the steps:

  • Go to the C:\Users\UserName.m2 directory and remove everything.
  • In Eclipse, right click on the project, Run As > Maven Build… and type clear install in the Goals field, and Run
  • Expect to load all dependencies.
  • Change the SDK to 1.8.0_221.

Hope this helps.

This has just happened for me.
I’m on spring-core/5.3.0-M1, spring-boot/2.4.0-M1.
If it helps, it started happening after I added a class implementing ApplicationContextAware to provide access to Beans from outside Spring code, as described in this article.

I have the same issue when I use spring.profiles.active property, without it, works perfectly

I use spring 2.3.0 and java 11.0.2

java -version
openjdk version "11.0.2" 2019-01-15
OpenJDK Runtime Environment 18.9 (build 11.0.2+9)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.2+9, mixed mode)
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.sun.xml.bind.v2.runtime.reflect.opt.Injector (file:~/.gradle/caches/modules-2/files-2.1/com.sun.xml.bind/jaxb-impl/2.3.0.1/2e979dabb3e5e74a0686115075956391a14dece8/jaxb-impl-2.3.0.1.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int)
WARNING: Please consider reporting this to the maintainers of com.sun.xml.bind.v2.runtime.reflect.opt.Injector
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

Using latest Spring boot with self auto-wiring a service (singleton bean) caused to show this message

Spring boot 2.2.6.RELEASE

A quick update: See my comment at https://github.com/spring-projects/spring-framework/issues/22814#issuecomment-762862757 - We’re fine-tuning our defineClass handling for Boot’s DevTools where a significant number of warnings comes from at the moment. Proxying for JDK library classes remains tough, as explained there as well.

Please note that many scenarios are going to work ok even with --illegal-access=deny in JDK 16 since we have a fallback in place once our defineClass attempt fails. Nevertheless, we’d like to address all remaining Boot scenarios so that we do not need to reflectively call ClassLoader.defineClass at all anymore, avoiding warnings with --illegal-access=warn.

An easy way out is also --add-opens java.base/java.lang=ALL-UNNAMED on JVM startup, getting rid of the warning in any scenario and also making any scenario work with --illegal-access=deny. All we’re trying to do is improve the default experience with Spring Boot 2.4.x / 2.5 on Spring Framework 5.3.x, given the advent of JDK 16 and then JDK 17 LTS.

Azul Zulu 11.0.6 Zulu 11.37+17 4c3a2c98f1f6 OpenJSSE 1.1.2 549936e0c69481addad323098e23f307a0e98bce Spring Boot 2.2.4.RELEASE / on latest 2.2.*

WARNING: An illegal reflective access operation has occurred WARNING: Illegal reflective access by org.springframework.cglib.core.ReflectUtils (file:/C:/Users/talos/.m2/repository/org/springframework/spring-core/5.2.4.RELEASE/spring-core-5.2.4.RELEASE.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) WARNING: Please consider reporting this to the maintainers of org.springframework.cglib.core.ReflectUtils WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations WARNING: All illegal access operations will be denied in a future release