• <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 中?

        How to hide warning quot;Illegal reflective accessquot; in java 9 without JVM argument?(如何隐藏警告“非法反射访问在没有 JVM 参数的 java 9 中?)

        <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 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Bytecode features not available in the Java language(Java 语言中不可用的字节码功能)
                  ClassCastException because of classloaders?(ClassCastException 因为类加载器?)
                  How can I add a Javaagent to a JVM without stopping the JVM?(如何在不停止 JVM 的情况下将 Javaagent 添加到 JVM?)
                  Cannot load 64-bit SWT libraries on 32-bit JVM ( replacing SWT file )(无法在 32 位 JVM 上加载 64 位 SWT 库(替换 SWT 文件))
                  Encourage the JVM to GC rather than grow the heap?(鼓励 JVM 进行 GC 而不是增加堆?)
                  Why a sawtooth shaped graph?(为什么是锯齿形图形?)
                  <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>
                            <tbody id='Vx0Bt'></tbody>

                            <bdo id='Vx0Bt'></bdo><ul id='Vx0Bt'></ul>
                          • <small id='Vx0Bt'></small><noframes id='Vx0Bt'>