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

<tfoot id='FlM94'></tfoot>

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

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

        IntStream 何时真正关闭?SonarQube S2095 是 IntStream 的误报吗?

        When is an IntStream actually closed? Is SonarQube S2095 a false positive for IntStream?(IntStream 何时真正关闭?SonarQube S2095 是 IntStream 的误报吗?)
        • <bdo id='l6Lp9'></bdo><ul id='l6Lp9'></ul>
          <i id='l6Lp9'><tr id='l6Lp9'><dt id='l6Lp9'><q id='l6Lp9'><span id='l6Lp9'><b id='l6Lp9'><form id='l6Lp9'><ins id='l6Lp9'></ins><ul id='l6Lp9'></ul><sub id='l6Lp9'></sub></form><legend id='l6Lp9'></legend><bdo id='l6Lp9'><pre id='l6Lp9'><center id='l6Lp9'></center></pre></bdo></b><th id='l6Lp9'></th></span></q></dt></tr></i><div id='l6Lp9'><tfoot id='l6Lp9'></tfoot><dl id='l6Lp9'><fieldset id='l6Lp9'></fieldset></dl></div>

          1. <small id='l6Lp9'></small><noframes id='l6Lp9'>

          2. <legend id='l6Lp9'><style id='l6Lp9'><dir id='l6Lp9'><q id='l6Lp9'></q></dir></style></legend>
            <tfoot id='l6Lp9'></tfoot>

                <tbody id='l6Lp9'></tbody>
                  本文介绍了IntStream 何时真正关闭?SonarQube S2095 是 IntStream 的误报吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用 Java 8 流代替许多旧样式的 for 循环来迭代一堆结果并生成汇总统计信息.例如:

                  I am using Java 8 streams in place of many old style for loops to iterate through a bunch of results and produce summary statistics. For example:

                  int messages = IntStream.rangeClosed(0, 7).map(ids::get).reduce(Integer::sum).getAsInt();
                  

                  注意:我知道还有其他方法可以进行上面显示的计数.我这样做是为了说明我的问题.

                  我正在使用带有 Java 3.9 插件的 SonarQube 5.3.在该配置中,上面的代码行违反了 squid 规则 S2095:资源应该关闭."这就是我希望看到 AutoCloseable(例如 FileInputStream)是否已打开但从未关闭的结果.

                  I am using SonarQube 5.3 with the Java 3.9 plugin. In that configuration, the above line of code gives me a violation of squid rule S2095: "Resources should be closed." That's the result I would expect to see if an AutoCloseable (e.g., a FileInputStream) was opened but never closed.

                  所以这是我的问题:终端操作 reduce 是否关闭流?应该是?或者这是鱿鱼规则中的误报?

                  So here's my question: does the terminal operation reduce close the stream? Should it? Or is this a false positive in the squid rule?

                  推荐答案

                  它没有关闭,因为 AutoCloseable 接口只在 try-with-resources 内部工作.但是正如 AutoCloseable 接口 javadoc 中所说的那样,对于 IntStream 来说,这种关闭操作是完全没有必要的:

                  It isn't closed, because AutoCloseable interface works only inside try-with-resources. But this close operation is totally unnecessary for IntStream as it said in AutoCloseable interface javadoc:

                  但是,当使用 java.util.stream.Stream 等工具时,支持基于 I/O 和非基于 I/O 的形式,try-with-resources使用非基于 I/O 的表单时,通常不需要块.

                  However, when using facilities such as java.util.stream.Stream that support both I/O-based and non-I/O-based forms, try-with-resources blocks are in general unnecessary when using non-I/O-based forms.

                  所以是的 S2095 是 IntStream 的误报.SONARJAVA-1478

                  So yes S2095 is a false positive for IntStream. That will be hopefully fixed by SONARJAVA-1478

                  这篇关于IntStream 何时真正关闭?SonarQube S2095 是 IntStream 的误报吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
                  How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
                  Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
                  Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
                  How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
                  How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)

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

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