代码之家  ›  专栏  ›  技术社区  ›  xpt

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

  •  0
  • xpt  · 技术社区  · 4 年前

    问题与 Groovy - WARNING: An illegal reflective access operation has occurred 就这样

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

    如何摆脱这个警告信息?

    1 回复  |  直到 4 年前
        1
  •  0
  •   swpalmer    4 年前

    从FileNotFound异常中可以清楚地看到,--add opens没有用作JVM标志。 你试过设置JAVA_选项吗?就像这样:

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

        2
  •  -1
  •   Abdul Momen    4 年前
    export JAVA_OPTS="--add-opens java.base/java.lang=ALL-UNNAMED"
    groovy --version