• <bdo id='NoGxc'></bdo><ul id='NoGxc'></ul>
      <legend id='NoGxc'><style id='NoGxc'><dir id='NoGxc'><q id='NoGxc'></q></dir></style></legend>
    1. <i id='NoGxc'><tr id='NoGxc'><dt id='NoGxc'><q id='NoGxc'><span id='NoGxc'><b id='NoGxc'><form id='NoGxc'><ins id='NoGxc'></ins><ul id='NoGxc'></ul><sub id='NoGxc'></sub></form><legend id='NoGxc'></legend><bdo id='NoGxc'><pre id='NoGxc'><center id='NoGxc'></center></pre></bdo></b><th id='NoGxc'></th></span></q></dt></tr></i><div id='NoGxc'><tfoot id='NoGxc'></tfoot><dl id='NoGxc'><fieldset id='NoGxc'></fieldset></dl></div>
      <tfoot id='NoGxc'></tfoot>

      <small id='NoGxc'></small><noframes id='NoGxc'>

      1. 如何隐藏警告“非法反射访问"在没有 JVM 参数的 java 9 中?

        时间:2023-08-24

        <tfoot id='MTxkD'></tfoot>

        • <bdo id='MTxkD'></bdo><ul id='MTxkD'></ul>

                    <tbody id='MTxkD'></tbody>
                1. <small id='MTxkD'></small><noframes id='MTxkD'>

                  <legend id='MTxkD'><style id='MTxkD'><dir id='MTxkD'><q id='MTxkD'></q></dir></style></legend>

                2. <i id='MTxkD'><tr id='MTxkD'><dt id='MTxkD'><q id='MTxkD'><span id='MTxkD'><b id='MTxkD'><form id='MTxkD'><ins id='MTxkD'></ins><ul id='MTxkD'></ul><sub id='MTxkD'></sub></form><legend id='MTxkD'></legend><bdo id='MTxkD'><pre id='MTxkD'><center id='MTxkD'></center></pre></bdo></b><th id='MTxkD'></th></span></q></dt></tr></i><div id='MTxkD'><tfoot id='MTxkD'></tfoot><dl id='MTxkD'><fieldset id='MTxkD'></fieldset></dl></div>
                  本文介绍了如何隐藏警告“非法反射访问"在没有 JVM 参数的 java 9 中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我刚刚尝试使用 Java 9 运行我的服务器并收到下一个警告:

                  I just tried to run my server with Java 9 and got next warning:

                  WARNING: An illegal reflective access operation has occurred
                  WARNING: Illegal reflective access by io.netty.util.internal.ReflectionUtil (file:/home/azureuser/server-0.28.0-SNAPSHOT.jar) to constructor java.nio.DirectByteBuffer(long,int)
                  WARNING: Please consider reporting this to the maintainers of io.netty.util.internal.ReflectionUtil
                  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
                  

                  我想隐藏此警告,而不在启动期间将 --illegal-access=deny 添加到 JVM 选项.比如:

                  I would like to hide this warning without adding --illegal-access=deny to JVM options during start. Something like:

                  System.setProperty("illegal-access", "deny");
                  

                  有什么办法吗?

                  建议使用 JVM 选项的所有相关答案,我想从代码中关闭它.这可能吗?

                  All related answers suggesting to use JVM options, I would like to turn off this from code. Is that possible?

                  澄清一下 - 我的问题是关于从代码中转换此警告,而不是通过类似问题中所述的 JVM 参数/标志.

                  To clarify - my question is about turning this warning from the code and not via JVM arguments/flags as stated in similar questions.

                  推荐答案

                  有一些方法可以禁用非法访问警告,但我不建议这样做.

                  There are ways to disable illegal access warning, though I do not recommend doing this.

                  由于警告打印到默认错误流,您可以简单地关闭此流并将 stderr 重定向到 stdout.

                  Since the warning is printed to the default error stream, you can simply close this stream and redirect stderr to stdout.

                  public static void disableWarning() {
                      System.err.close();
                      System.setErr(System.out);
                  }
                  

                  注意事项:

                  • 这种方法合并了错误流和输出流.在某些情况下,这可能是不可取的.
                  • 您不能仅通过调用 System.setErr 来重定向警告消息,因为对错误流的引用在 JVM 引导的早期保存在 IllegalAccessLogger.warningStream 字段中.
                  • This approach merges error and output streams. That may not be desirable in some cases.
                  • You cannot redirect warning message just by calling System.setErr, since the reference to error stream is saved in IllegalAccessLogger.warningStream field early at JVM bootstrap.

                  一个好消息是 sun.misc.Unsafe 仍然可以在 JDK 9 中访问而不会出现警告.解决方案是借助 Unsafe API 重置内部 IllegalAccessLogger.

                  A good news is that sun.misc.Unsafe can be still accessed in JDK 9 without warnings. The solution is to reset internal IllegalAccessLogger with the help of Unsafe API.

                  public static void disableWarning() {
                      try {
                          Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
                          theUnsafe.setAccessible(true);
                          Unsafe u = (Unsafe) theUnsafe.get(null);
                  
                          Class cls = Class.forName("jdk.internal.module.IllegalAccessLogger");
                          Field logger = cls.getDeclaredField("logger");
                          u.putObjectVolatile(cls, u.staticFieldOffset(logger), null);
                      } catch (Exception e) {
                          // ignore
                      }
                  }
                  

                  这篇关于如何隐藏警告“非法反射访问"在没有 JVM 参数的 java 9 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在 Dalvik VM(Android 的 VM)上,您不能在 Sun VM 中做什么? 下一篇:减小 JRE 的大小

                  相关文章

                  <i id='Vx0Bt'><tr id='Vx0Bt'><dt id='Vx0Bt'><q id='Vx0Bt'><span id='Vx0Bt'><b id='Vx0Bt'><form id='Vx0Bt'><ins id='Vx0Bt'></ins><ul id='Vx0Bt'></ul><sub id='Vx0Bt'></sub></form><legend id='Vx0Bt'></legend><bdo id='Vx0Bt'><pre id='Vx0Bt'><center id='Vx0Bt'></center></pre></bdo></b><th id='Vx0Bt'></th></span></q></dt></tr></i><div id='Vx0Bt'><tfoot id='Vx0Bt'></tfoot><dl id='Vx0Bt'><fieldset id='Vx0Bt'></fieldset></dl></div>

                      <tfoot id='Vx0Bt'></tfoot>
                      <legend id='Vx0Bt'><style id='Vx0Bt'><dir id='Vx0Bt'><q id='Vx0Bt'></q></dir></style></legend>
                      • <bdo id='Vx0Bt'></bdo><ul id='Vx0Bt'></ul>
                    1. <small id='Vx0Bt'></small><noframes id='Vx0Bt'>