Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
511680fa
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
4
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_jdk
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
511680fa
编写于
8月 20, 2008
作者:
M
martin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
6739302: Check that deserialization preserves EnumSet integrity
Reviewed-by: dl, chegar Contributed-by: jjb@google.com
上级
b036a7c2
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
100 addition
and
0 deletion
+100
-0
src/share/classes/java/util/EnumSet.java
src/share/classes/java/util/EnumSet.java
+7
-0
test/java/util/EnumSet/BogusEnumSet.java
test/java/util/EnumSet/BogusEnumSet.java
+93
-0
未找到文件。
src/share/classes/java/util/EnumSet.java
浏览文件 @
511680fa
...
@@ -432,4 +432,11 @@ public abstract class EnumSet<E extends Enum<E>> extends AbstractSet<E>
...
@@ -432,4 +432,11 @@ public abstract class EnumSet<E extends Enum<E>> extends AbstractSet<E>
Object
writeReplace
()
{
Object
writeReplace
()
{
return
new
SerializationProxy
<
E
>(
this
);
return
new
SerializationProxy
<
E
>(
this
);
}
}
// readObject method for the serialization proxy pattern
// See Effective Java, Second Ed., Item 78.
private
void
readObject
(
java
.
io
.
ObjectInputStream
stream
)
throws
java
.
io
.
InvalidObjectException
{
throw
new
java
.
io
.
InvalidObjectException
(
"Proxy required"
);
}
}
}
test/java/util/EnumSet/BogusEnumSet.java
0 → 100644
浏览文件 @
511680fa
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 6739302
* @summary Check that deserialization preserves EnumSet integrity
* @author Josh Bloch
*/
import
java.util.*
;
import
java.io.*
;
public
class
BogusEnumSet
{
public
static
void
main
(
String
[]
args
)
throws
Throwable
{
byte
[]
serializedForm
=
{
(
byte
)
0xac
,
(
byte
)
0xed
,
0x0
,
0x5
,
0x73
,
0x72
,
0x0
,
0x18
,
0x6a
,
0x61
,
0x76
,
0x61
,
0x2e
,
0x75
,
0x74
,
0x69
,
0x6c
,
0x2e
,
0x52
,
0x65
,
0x67
,
0x75
,
0x6c
,
0x61
,
0x72
,
0x45
,
0x6e
,
0x75
,
0x6d
,
0x53
,
0x65
,
0x74
,
0x2f
,
0x58
,
0x6f
,
(
byte
)
0xc7
,
0x7e
,
(
byte
)
0xb0
,
(
byte
)
0xd0
,
0x7e
,
0x2
,
0x0
,
0x1
,
0x4a
,
0x0
,
0x8
,
0x65
,
0x6c
,
0x65
,
0x6d
,
0x65
,
0x6e
,
0x74
,
0x73
,
0x78
,
0x72
,
0x0
,
0x11
,
0x6a
,
0x61
,
0x76
,
0x61
,
0x2e
,
0x75
,
0x74
,
0x69
,
0x6c
,
0x2e
,
0x45
,
0x6e
,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,
0x61
,
0x2e
,
0x6c
,
0x61
,
0x6e
,
0x67
,
0x2e
,
0x54
,
0x68
,
0x72
,
0x65
,
0x61
,
0x64
,
0x24
,
0x53
,
0x74
,
0x61
,
0x74
,
0x65
,
0x3b
,
0x68
,
(
byte
)
0xa3
,
(
byte
)
0xb5
,
(
byte
)
0xd5
,
0x11
,
0x7d
,
0x1b
,
(
byte
)
0xb3
,
0x2
,
0x0
,
0x0
,
0x78
,
0x70
,
0x0
,
0x0
,
0x0
,
0x6
,
0x7e
,
0x71
,
0x0
,
0x7e
,
0x0
,
0x5
,
0x74
,
0x0
,
0x3
,
0x4e
,
0x45
,
0x57
,
0x7e
,
0x71
,
0x0
,
0x7e
,
0x0
,
0x5
,
0x74
,
0x0
,
0x8
,
0x52
,
0x55
,
0x4e
,
0x4e
,
0x41
,
0x42
,
0x4c
,
0x45
,
0x7e
,
0x71
,
0x0
,
0x7e
,
0x0
,
0x5
,
0x74
,
0x0
,
0x7
,
0x42
,
0x4c
,
0x4f
,
0x43
,
0x4b
,
0x45
,
0x44
,
0x7e
,
0x71
,
0x0
,
0x7e
,
0x0
,
0x5
,
0x74
,
0x0
,
0x7
,
0x57
,
0x41
,
0x49
,
0x54
,
0x49
,
0x4e
,
0x47
,
0x7e
,
0x71
,
0x0
,
0x7e
,
0x0
,
0x5
,
0x74
,
0x0
,
0xd
,
0x54
,
0x49
,
0x4d
,
0x45
,
0x44
,
0x5f
,
0x57
,
0x41
,
0x49
,
0x54
,
0x49
,
0x4e
,
0x47
,
0x7e
,
0x71
,
0x0
,
0x7e
,
0x0
,
0x5
,
0x74
,
0x0
,
0xa
,
0x54
,
0x45
,
0x52
,
0x4d
,
0x49
,
0x4e
,
0x41
,
0x54
,
0x45
,
0x44
,
(
byte
)
0xff
,
(
byte
)
0xff
,
(
byte
)
0xff
,
(
byte
)
0xff
,
(
byte
)
0xff
,
(
byte
)
0xff
,
(
byte
)
0xff
,
(
byte
)
0xff
};
try
{
// Should fail, but instead creates corrupt EnumSet
@SuppressWarnings
(
"unchecked"
)
EnumSet
<
Thread
.
State
>
es
=
(
EnumSet
<
Thread
.
State
>)
deserialize
(
serializedForm
);
// Demonstrates corruption
System
.
out
.
println
(
"Enum size: "
+
Thread
.
State
.
values
().
length
);
// 6
System
.
out
.
println
(
"Set size: "
+
es
.
size
());
// 64
System
.
out
.
println
(
"Set: "
+
es
);
// Throws IndexOutOfBoundsException
throw
new
AssertionError
(
"Expected exception InvalidObjectException not thrown"
);
}
catch
(
java
.
io
.
InvalidObjectException
_
)
{
/* OK */
}
}
private
static
Object
deserialize
(
byte
[]
sf
)
throws
Throwable
{
return
new
ObjectInputStream
(
new
ByteArrayInputStream
(
sf
))
.
readObject
();
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录