【发布时间】:2015-04-22 20:07:43
【问题描述】:
在我的代码中,我有以下行:
private int[][][] shapes;
在野外,它存在于一个枚举中:
public enum TetrisGamePiece {
private int id;
private int pieceColour;
private int[][][] shapes; // <-- This line is not accepted
private TetrisGamePiece(int id, int colour, int[][] shape1, int[][] shape2, int[][] shape3, int[][] shape4) {
this.id = id;
this.pieceColour = colour;
this.shapes = new int[][][]{shape1, shape2, shape3, shape4};
}
// ... the rest of the enum ...
// i've left out instantiation of objects to save space.
我从 sonarqube 得到以下提及:
使“形状”瞬态或可序列化。可序列化的字段 类本身必须是可序列化的或瞬态的,即使 类从不显式序列化或反序列化。那是因为 在负载下,大多数 J2EE 应用程序框架将对象刷新到磁盘, 和一个据称具有非瞬态的可序列化对象, 不可序列化的数据成员可能会导致程序崩溃,并打开 攻击者的大门。
据我所知,int[](和 int[][] 等)是可序列化的。这是 sonarqube 中的错误还是我误解了基本类型数组的可序列化性?
编辑:添加它所在的枚举,以防枚举类型相关
【问题讨论】:
-
听起来像是 sonarqube 中的一个错误。
-
@jtahlborn 谢谢 :) 我有点怀疑自己的理智
-
确实,所有原语及其包装器在 java 中都是可序列化的,它们的数组也是如此。
-
嘿,去过。当它看起来太明显时,您有时会怀疑自己是否遗漏了什么!
-
这个问题值得留给别人,还是没有任何价值?
标签: java sonarqube serializable