Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
51593e7d
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看板
提交
51593e7d
编写于
4月 25, 2013
作者:
D
darcy
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8012044: Give more information about self-suppression from Throwable.addSuppressed
Reviewed-by: alanb, dholmes
上级
ff97235b
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
43 addition
and
7 deletion
+43
-7
src/share/classes/java/lang/Throwable.java
src/share/classes/java/lang/Throwable.java
+5
-4
test/java/lang/Throwable/SuppressedExceptions.java
test/java/lang/Throwable/SuppressedExceptions.java
+38
-3
未找到文件。
src/share/classes/java/lang/Throwable.java
浏览文件 @
51593e7d
/*
/*
* Copyright (c) 1994, 201
2
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1994, 201
3
, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
*
* This code is free software; you can redistribute it and/or modify it
* This code is free software; you can redistribute it and/or modify it
...
@@ -453,9 +453,10 @@ public class Throwable implements Serializable {
...
@@ -453,9 +453,10 @@ public class Throwable implements Serializable {
*/
*/
public
synchronized
Throwable
initCause
(
Throwable
cause
)
{
public
synchronized
Throwable
initCause
(
Throwable
cause
)
{
if
(
this
.
cause
!=
this
)
if
(
this
.
cause
!=
this
)
throw
new
IllegalStateException
(
"Can't overwrite cause"
);
throw
new
IllegalStateException
(
"Can't overwrite cause with "
+
Objects
.
toString
(
cause
,
"a null"
),
this
);
if
(
cause
==
this
)
if
(
cause
==
this
)
throw
new
IllegalArgumentException
(
"Self-causation not permitted"
);
throw
new
IllegalArgumentException
(
"Self-causation not permitted"
,
this
);
this
.
cause
=
cause
;
this
.
cause
=
cause
;
return
this
;
return
this
;
}
}
...
@@ -1039,7 +1040,7 @@ public class Throwable implements Serializable {
...
@@ -1039,7 +1040,7 @@ public class Throwable implements Serializable {
*/
*/
public
final
synchronized
void
addSuppressed
(
Throwable
exception
)
{
public
final
synchronized
void
addSuppressed
(
Throwable
exception
)
{
if
(
exception
==
this
)
if
(
exception
==
this
)
throw
new
IllegalArgumentException
(
SELF_SUPPRESSION_MESSAGE
);
throw
new
IllegalArgumentException
(
SELF_SUPPRESSION_MESSAGE
,
exception
);
if
(
exception
==
null
)
if
(
exception
==
null
)
throw
new
NullPointerException
(
NULL_CAUSE_MESSAGE
);
throw
new
NullPointerException
(
NULL_CAUSE_MESSAGE
);
...
...
test/java/lang/Throwable/SuppressedExceptions.java
浏览文件 @
51593e7d
/*
/*
* Copyright (c) 2010, 201
1
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 201
3
, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
*
* This code is free software; you can redistribute it and/or modify it
* This code is free software; you can redistribute it and/or modify it
...
@@ -26,7 +26,7 @@ import java.util.*;
...
@@ -26,7 +26,7 @@ import java.util.*;
/*
/*
* @test
* @test
* @bug 6911258 6962571 6963622 6991528 7005628
* @bug 6911258 6962571 6963622 6991528 7005628
8012044
* @summary Basic tests of suppressed exceptions
* @summary Basic tests of suppressed exceptions
* @author Joseph D. Darcy
* @author Joseph D. Darcy
*/
*/
...
@@ -40,6 +40,7 @@ public class SuppressedExceptions {
...
@@ -40,6 +40,7 @@ public class SuppressedExceptions {
serializationTest
();
serializationTest
();
selfReference
();
selfReference
();
noModification
();
noModification
();
initCausePlumbing
();
}
}
private
static
void
noSelfSuppression
()
{
private
static
void
noSelfSuppression
()
{
...
@@ -48,7 +49,9 @@ public class SuppressedExceptions {
...
@@ -48,7 +49,9 @@ public class SuppressedExceptions {
throwable
.
addSuppressed
(
throwable
);
throwable
.
addSuppressed
(
throwable
);
throw
new
RuntimeException
(
"IllegalArgumentException for self-suppresion not thrown."
);
throw
new
RuntimeException
(
"IllegalArgumentException for self-suppresion not thrown."
);
}
catch
(
IllegalArgumentException
iae
)
{
}
catch
(
IllegalArgumentException
iae
)
{
;
// Expected
// Expected to be here
if
(
iae
.
getCause
()
!=
throwable
)
throw
new
RuntimeException
(
"Bad cause after self-suppresion."
);
}
}
}
}
...
@@ -208,4 +211,36 @@ public class SuppressedExceptions {
...
@@ -208,4 +211,36 @@ public class SuppressedExceptions {
super
(
"The medium."
,
null
,
enableSuppression
,
true
);
super
(
"The medium."
,
null
,
enableSuppression
,
true
);
}
}
}
}
private
static
void
initCausePlumbing
()
{
Throwable
t1
=
new
Throwable
();
Throwable
t2
=
new
Throwable
(
"message"
,
t1
);
Throwable
t3
=
new
Throwable
();
try
{
t2
.
initCause
(
t3
);
throw
new
RuntimeException
(
"Shouldn't reach."
);
}
catch
(
IllegalStateException
ise
)
{
if
(
ise
.
getCause
()
!=
t2
)
throw
new
RuntimeException
(
"Unexpected cause in ISE"
,
ise
);
Throwable
[]
suppressed
=
ise
.
getSuppressed
();
if
(
suppressed
.
length
!=
0
)
throw
new
RuntimeException
(
"Bad suppression in ISE"
,
ise
);
}
try
{
t2
.
initCause
(
null
);
throw
new
RuntimeException
(
"Shouldn't reach."
);
}
catch
(
IllegalStateException
ise
)
{
;
// Expected; don't want an NPE.
}
try
{
t3
.
initCause
(
t3
);
throw
new
RuntimeException
(
"Shouldn't reach."
);
}
catch
(
IllegalArgumentException
iae
)
{
if
(
iae
.
getCause
()
!=
t3
)
throw
new
RuntimeException
(
"Unexpected cause in ISE"
,
iae
);
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录