天天看點

IDEA 報錯:An illegal reflective access operation has occurred

作者:葉斌兵

現象

idea啟動項目時出現警告:

"/Applications/IntelliJ IDEA.app/Contents/jbr/Contents/Home/bin/java" ...

Connected to the target VM, address: 'www.ybb.press:62251', transport: 'socket'

WARNING: An illegal reflective access operation has occurred

WARNING: Illegal reflective access by com.google.inject.internal.cglib.core.$ReflectUtils$1 (file:/Users/lizz/.m2/repository/com/google/inject/guice/4.1.0/guice-4.1.0.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 com.google.inject.internal.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

原因分析

錯誤提示:com.google.inject.internal.cglib.core.$ReflectUtils$1通路了java.lang.ClassLoader類。

因為JDK9的新特性子產品系統(module system)對jdk中的子產品進行了反射檢查,對于反射了jdk中的類的操作進行警告。

處理辦法

方法一:降低jdk版本

将idea中的項目運作環境從高版本調整為JDK8即可,如果moudle格式,可能還需要将每個moudle單獨設定。

File>Project Structure>Project Settings>Project>Project SDK

IDEA 報錯:An illegal reflective access operation has occurred

方法二:開放通路權限

JDK9+可以使用啟動參數中增加“--add-opens <package>/<class>=ALL-UNNAMED”的方法允許其他子產品通路。

在RUN>Edit Configurations>VM options 中增加參數,如:

--add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.base/java.text=ALL-UNNAMED --add-opens java.desktop/java.awt.font=ALL-UNNAMED

IDEA 報錯:An illegal reflective access operation has occurred
IDEA 報錯:An illegal reflective access operation has occurred