【问题标题】:groovy WARNING: An illegal reflective access operation has occurred under Ubuntugroovy WARNING: Ubuntu下发生了非法反射访问操作
【发布时间】:2022-01-22 09:53:08
【问题描述】:

同样的问题 Groovy - WARNING: An illegal reflective access operation has occurred,就是这样

  • 这是在 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.

如何摆脱该警告信息?

【问题讨论】:

  • Groovy 2.4.21 有很多这样的问题。 Groovy 2.5 和 3 以及很快 4 都在使用方法句柄和其他适当的访问机制方面取得了长足的进步。
  • 使用 groovy 3.0 更好地使用 java 11。 groovy 2.5 开始支持 java 9。为 java 8 设计的 groovy 2.4。groovy-lang.org/releasenotes/groovy-2.5.html
  • 谢谢@daggett,我想你已经搞定了。只是我最新的 Ubuntu 21.10 仍然只提供 groovy-2.4.21。出于这个特殊原因,我想我会使用 java 8(由 openjdk-8-jdk:amd64 提供)而不是使用外部 sdkman 工具安装 groovy 3.0,因为我只需要一些东西来工作,不需要成为最新最好的,Java 8 对我来说很好。谢了!

标签: java ubuntu groovy java-11


【解决方案1】:
export JAVA_OPTS="--add-opens java.base/java.lang=ALL-UNNAMED"
groovy --version

【讨论】:

  • 确实,“在为在 Grails 环境上设置 Groovy 苦苦挣扎了几天之后,我觉得我知道答案了:现在使用 JDK 8。” 这可能是 只有可行的选择。我再等几天看看...
【解决方案2】:

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

【讨论】:

  • 看来 --add-opens 还不够。我已经更新了我的答案,因为我从你那里得到了不同的结果。而且我看到 groovy 并没有抱怨 Java 17。
  • 谢谢,你能列出你的 java / groovy 版本和你的操作系统细节吗?
  • @xpt Java 17.0.1,groovy 2.4.17,Ubuntu 20.04
  • thx 和 “我实际上仍然收到反射访问警告”,请问那个 Java 版本是什么?
  • @xpt 仍然收到 JVM 11.0.13 的警告
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-02-24
  • 2021-08-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-01-10
相关资源
最近更新 更多