與Groovy相同的問題 - 警告:發生非法反射訪問操作,僅此而已
- 這是在 Ubuntu 21.10
- 最重要的是,該解決方案(傳遞
--add-opens給 JVM),我無法讓它為我作業。
$ groovy -version
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.reflection.CachedClass (file:/usr/share/groovy/lib/groovy-2.4.21.jar) to method java.lang.Object.finalize()
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.reflection.CachedClass
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
Groovy Version: 2.4.21 JVM: 11.0.12 Vendor: Ubuntu OS: Linux
$ java -version
openjdk version "11.0.12" 2021-07-20
OpenJDK Runtime Environment (build 11.0.12 7-Ubuntu-0ubuntu3)
OpenJDK 64-Bit Server VM (build 11.0.12 7-Ubuntu-0ubuntu3, mixed mode, sharing)
$ java --add-opens java.base/java.lang=ALL-UNNAMED -version
openjdk version "11.0.12" 2021-07-20
OpenJDK Runtime Environment (build 11.0.12 7-Ubuntu-0ubuntu3)
OpenJDK 64-Bit Server VM (build 11.0.12 7-Ubuntu-0ubuntu3, mixed mode, sharing)
$ groovy --add-opens java.base/java.lang=ALL-UNNAMED -version
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.reflection.CachedClass (file:/usr/share/groovy/lib/groovy-2.4.21.jar) to method java.lang.Object.finalize()
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.reflection.CachedClass
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
Caught: java.io.FileNotFoundException: /export/home/me/--add-opens (/export/home/me/--add-opens)
java.io.FileNotFoundException: /export/home/me/--add-opens (/export/home/me/--add-opens)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
$ apt-cache policy groovy
groovy:
Installed: 2.4.21-1
Candidate: 2.4.21-1
Version table:
*** 2.4.21-1 500
500 http://archive.ubuntu.com/ubuntu impish/universe amd64 Packages
500 http://archive.ubuntu.com/ubuntu impish/universe i386 Packages
100 /var/lib/dpkg/status
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 21.10
Release: 21.10
Codename: impish
更新,我也嘗試設定JAVA_OPTS:
export JAVA_OPTS="--add-opens java.base/java.lang=ALL-UNNAMED"
$ groovy -version
Unrecognized option: --add-opens
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
如何擺脫該警告訊息?
uj5u.com熱心網友回復:
從 FileNotFound 例外中可以清楚地看出 --add-opens 沒有用作 JVM 標志。您是否嘗試過設定 JAVA_OPTS?像這樣:
export JAVA_OPTS="--add-opens java.base/java.lang=ALL-UNNAMED"
groovy --version
我沒有和你一樣的錯誤。我實際上仍然收到反射訪問警告,而不是關于--add-opens無法識別的錯誤。即使--illegal-access=permit我仍然看到警告。奇怪的。我確定正在使用 JAVA_OPTS 值,因為如果我將其設定為無效標志,它確實會抱怨。
你有定義 JAVA_HOME 嗎?我注意到 groovy 也會選擇該值來選擇 JVM。
使用 Java 17 我沒有收到警告或錯誤。
uj5u.com熱心網友回復:
export JAVA_OPTS="--add-opens java.base/java.lang=ALL-UNNAMED"
groovy --version
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/389963.html
