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

Jan Nielsen picture Jan Nielsen · Oct 10, 2017 · Viewed 50.1k times · Source

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 JDK9: An illegal reflective access operation has occurred. org.python.core.PySystemState which deals with a similar symptom in a different library.

Answer

Jan Nielsen picture Jan Nielsen · Oct 10, 2017

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+.