繁体   English   中英

groovy 警告:在 Ubuntu 下发生了非法反射访问操作

[英]groovy WARNING: An illegal reflective access operation has occurred under Ubuntu

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.

如何摆脱该警告信息?

按照此处的说明进行操作: https://groovy-lang.org/install.html这将:

  • 安装 sdkman
    • 管理多个 JDK 和扩展
  • 在当前JDK中安装groovy

为我工作:

  • openjdk 11.0.11 2021-04-20
  • OpenJDK 运行环境(build 11.0.11+9-Ubuntu-0ubuntu2.20.04)
  • OpenJDK 64-Bit Server VM (build 11.0.11+9-Ubuntu-0ubuntu2.20.04, 混合模式, 共享)

从 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 我没有收到任何警告或错误。

It is more than a 'warning' for me: I cannot get Groovy scripts to run (on macOS) with the current JVM 9, much less 10. The workaround (until a compatible version of Groovy is available) is to install jenv and an Java的早期版本,所以你可以在需要的时候切换。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM