Illegal reflective access by org.springframework.cglib.core.ReflectUtils$1

JavaSpringSpring BootJava 9Java Module

Java Problem Overview


My JDK 9+181 Spring Boot 2.0.0.BUILD-SNAPSHOT CLI application displays this warning on startup:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.springframework.cglib.core.ReflectUtils$1 (jar:file:/home/jan/src/fm-cli/target/fm-cli-0.1.0-SNAPSHOT.jar!/BOOT-INF/lib/spring-core-5.0.0.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

This is a console application, so I need to disable this warning -- how can I do that?

Note: This question asks the specific question of how to disable this warning triggered by Spring; it is not a duplicate of https://stackoverflow.com/questions/46230413/jdk9-an-illegal-reflective-access-operation-has-occurred-org-python-core-pysys which deals with a similar symptom in a different library.

Java Solutions


Solution 1 - Java

In JDK 9+, add the following option to the JVM to disable the warning from Spring's use of CGLIB:

--add-opens java.base/java.lang=ALL-UNNAMED

for example:

java --add-opens java.base/java.lang=ALL-UNNAMED -jar target/*.jar

No need to report it; it's a known Spring bug.

This happens because the new JDK 9 module system detected an illegal access that will be disallowed sometime in the (near) future. You can read more about the JDK 9 Module system here.

Update:

A fix for this issue is available JDK 9+ with Spring 5.1+.

Solution 2 - Java

This also happened to me on JDK 11 and Spring Boot 2.2.1 (Spring Core 5.2.1).

What helped was removing the dependency to org.springframework.boot:spring-boot-devtools, as suggested in some comments to Spring Framework issue #22814.

Solution 3 - Java

Adding to Jan Nielsen answer above, if you are using Intellij and Spring Boot 2.0.3, which depends on Spring core 5.0.7, you are still stuck and do not have the fix.

The way out for me needed two things:

  • Add the --add-opens mentioned by Jan to your run/debug configuration. Just edit the configuration and look under Environment / VM Options. This takes care of silencing some of the "illegal access messages".

  • I also needed to add a dependency to the jaxb-api library. I got the hint from ValentinBossi comment on this spring github issue.

Solution 4 - Java

When using the spring initializer, make sure you use the latest version of Spring Boot. It automatically gets Spring core 5.1 or greater for you and you won't see the error when you run the project.

So you don't have to worry about editing any JVM configuration.

Solution 5 - Java

I'm sitting on these versions and I still see the WARNING:

  • SpringBoot 2.4.1
  • Spring Core FW: 5.3.2 (my parent pom is Spring Boot's, so this version is introduced by it, not manually set by me)
  • Java openjdk version "11.0.9.1" 2020-11-04

Removing the dependency from spring-boot-devtools also worked for me and the warning is no longer there at startup.

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-devtools</artifactId>
  <optional>true</optional>
</dependency>

... At the end of the day I was just using the automatic re-start from my IDE upon any change in the classpath and I can leave without it. The thing, though, is that theroreticatlly we should not worry about it, since according to Spring documentation:

> Developer tools are automatically disabled when running a fully packaged application. If your application is launched using java -jar or if it’s started using a special classloader, then it is considered a “production application”

So one could expect that when the application is launched from command line the warning should go away (I haven't verified that).

Solution 6 - Java

After these warnings, if your app is still not working then add this dependency to your pom.xml

<dependency>
	<groupId>javax.xml.bind</groupId>
	<artifactId>jaxb-api</artifactId>
	<version>2.3.0</version>
</dependency>

This helped me!!

Solution 7 - Java

If you use maven and spring, just please upgrade to Spring Framework 5.1+ / Spring Boot 2.1+.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJan NielsenView Question on Stackoverflow
Solution 1 - JavaJan NielsenView Answer on Stackoverflow
Solution 2 - JavaCos64View Answer on Stackoverflow
Solution 3 - JavaCoffee_fanView Answer on Stackoverflow
Solution 4 - JavaOnome SotuView Answer on Stackoverflow
Solution 5 - JavaWinterBootView Answer on Stackoverflow
Solution 6 - Javakalariya parikshithView Answer on Stackoverflow
Solution 7 - JavaicebergView Answer on Stackoverflow