<legend id='sLUZZ'><style id='sLUZZ'><dir id='sLUZZ'><q id='sLUZZ'></q></dir></style></legend>
  • <small id='sLUZZ'></small><noframes id='sLUZZ'>

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

          <bdo id='sLUZZ'></bdo><ul id='sLUZZ'></ul>

        <tfoot id='sLUZZ'></tfoot>

        枚举的字段是否必须是可序列化的?

        Does enum#39;s field have to be Serializable?(枚举的字段是否必须是可序列化的?)

          <tbody id='Erg9n'></tbody>
        <tfoot id='Erg9n'></tfoot>

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

                <bdo id='Erg9n'></bdo><ul id='Erg9n'></ul>

                  本文介绍了枚举的字段是否必须是可序列化的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在通过 SonarQube 5.1 版分析 Java SE 7 项目.

                  I'm analyzing Java SE 7 project by SonarQube version 5.1.

                  然后,我在下面的代码中遇到了 squid:S1948.

                  Then, I faced squid:S1948 on below code.

                  可序列化"类中的字段应该是瞬态的或可序列化的

                  可序列化类中的字段本身必须是可序列化或瞬态的,即使该类从未显式序列化或反序列化.这是因为在负载情况下,大多数 J2EE 应用程序框架会将对象刷新到磁盘,并且据称具有非瞬态、不可序列化数据成员的可序列化对象可能会导致程序崩溃,并为攻击者打开大门.

                  Fields in a Serializable class must themselves be either Serializable or transient even if the class is never explicitly serialized or deserialized. That's because under load, most J2EE application frameworks flush objects to disk, and an allegedly Serializable object with non-transient, non-serializable data members could cause program crashes, and open the door to attackers.

                  enum ShutterSpeed {
                     private final Rational value; // Make "value" transient or serializable.
                     ...
                  }
                  

                  我认为任何枚举字段都不会在 J2SE 5.0 中被序列化(枚举常量的序列化)

                  I think that any enum fields won't be serialized in J2SE 5.0 (Serialization of Enum Constants)

                  这是误报吗?

                  完整的代码和问题在这里.

                  推荐答案

                  其实是误报.枚举常量的序列化(你've提供了一个链接)说:

                  It is actually a false-positive. The Serialization of Enum Constants (which you've provided a link to) says that:

                  枚举常量的序列化方式与普通可序列化不同或可外化的对象.枚举常量的序列化形式仅由其名称组成;常量的字段值不是出现在表格中.

                  Enum constants are serialized differently than ordinary serializable or externalizable objects. The serialized form of an enum constant consists solely of its name; field values of the constant are not present in the form.

                  在我看来,将 Enum 的字段值标记为 transient 或让它们实现 Serializable 是没有意义的,因为它们永远不会被序列化,无论它们是标记为 transient 还是实现 Serializable.

                  As I see it, it doesn't make sense to mark Enum's field values as transient or make them implement Serializable, since they'll never get serialized, no matter if they're marked as transient or implement Serializable.

                  如果该分析工具迫使您做这两件事中的一件,那么您将编写无用的代码.如果我是你,我会尝试禁用 enums 的警告.

                  If that analyzing tool forces you to do one of these two things, then you'll be writing useless code. If I were you, I'd try to disable that warning for enums.

                  这篇关于枚举的字段是否必须是可序列化的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 中的默认语言环境设置以使其保持一致?)
                    <bdo id='JAMxO'></bdo><ul id='JAMxO'></ul>

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

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