Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_langtools
提交
a9f94fe7
D
dragonwell8_langtools
项目概览
openanolis
/
dragonwell8_langtools
通知
0
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_langtools
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
a9f94fe7
编写于
5月 14, 2013
作者:
S
sogoel
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8013163: Convert 4 tools multicatch tests to jtreg format
Reviewed-by: jjg
上级
a263be6e
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
208 addition
and
0 deletion
+208
-0
test/tools/javac/multicatch/Pos11.java
test/tools/javac/multicatch/Pos11.java
+132
-0
test/tools/javac/multicatch/Pos12.java
test/tools/javac/multicatch/Pos12.java
+76
-0
未找到文件。
test/tools/javac/multicatch/Pos11.java
0 → 100644
浏览文件 @
a9f94fe7
/*
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 8013163
* @author sogoel
* @summary Test multiple nested multi-catch blocks with Exception hierarchies
* @run main Pos11
*/
/*
* For this test, exception hierarchy used:
*
* Throwable
* / \
* Exception Error
* | | |
* A B D
* |
* C
* |
* E
* As an exception is thrown within a nested try-catch block, outer catch blocks
* will catch an exception or its child exceptions, so the same exception can
* be caught and rethrown multiple times.
*/
public
class
Pos11
{
public
static
String
results
=
""
;
public
static
String
sExpected
=
"-AB:A-AB:B-CD:C-AB:C-CD:D-Throwable:D-CD:E"
+
"-AB:E-Exception:Exception-Throwable:Exception"
;
enum
TestExceptions
{
A
(
"A"
),
B
(
"B"
),
C
(
"C"
),
D
(
"D"
),
E
(
"E"
),
U
(
"U"
);
String
exType
;
TestExceptions
(
String
type
)
{
this
.
exType
=
type
;
}
}
public
static
void
main
(
String
...
args
)
{
Pos11
pos11
=
new
Pos11
();
for
(
TestExceptions
t
:
TestExceptions
.
values
())
{
pos11
.
rethrower
(
t
.
exType
);
}
if
(
results
.
compareTo
(
sExpected
)
!=
0
)
throw
new
RuntimeException
(
"FAIL: final strings did not match:\n"
+
results
+
"!=\n"
+
sExpected
);
System
.
out
.
println
(
"PASS"
);
}
void
rethrower
(
String
T
)
{
try
{
/* try1 */
try
{
/* try2 */
try
{
/* try3 */
try
{
/* try4 */
switch
(
T
)
{
case
"A"
:
throw
new
A
();
case
"B"
:
throw
new
B
();
case
"C"
:
throw
new
C
();
case
"D"
:
throw
new
D
();
case
"E"
:
throw
new
E
();
default
:
throw
new
Exception
(
new
Throwable
());
}
}
catch
(
final
C
|
D
cd
)
{
results
=
results
.
concat
(
"-CD:"
+
cd
.
getClass
().
getSimpleName
());
throw
cd
;
}
}
catch
(
final
A
|
B
ab
)
{
results
=
results
.
concat
(
"-AB:"
+
ab
.
getClass
().
getSimpleName
());
}
}
catch
(
final
Exception
e
)
{
results
=
results
.
concat
(
"-Exception:"
+
e
.
getClass
().
getSimpleName
());
throw
e
;
}
}
catch
(
Throwable
t
)
{
results
=
results
.
concat
(
"-Throwable:"
+
t
.
getClass
().
getSimpleName
());
}
}
// Test Exception
static
class
A
extends
Exception
{}
// Test Exception
static
class
B
extends
Exception
{}
// Test Exception
static
class
C
extends
B
{}
// Not a descendant of Exception
static
class
D
extends
Error
{}
// Test Exception
static
class
E
extends
C
{}
}
test/tools/javac/multicatch/Pos12.java
0 → 100644
浏览文件 @
a9f94fe7
/*
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 8013163
* @author sogoel
* @summary Child exception can be caught in a parents catch block but not sibling exceptions.
* @run main Pos12
*/
/*
* For this test:
* RuntimeException
* |
* A
* / \
* Ab Ac
* This test throws an Ab and catches it as an A(parent).
* The exception, although catch as an A, is rethrown and eventually
* caught as an Ab. Before that it is NOT caught as an Ac.
*/
public
class
Pos12
{
public
static
void
main
(
String
...
args
)
{
try
{
new
Pos12
().
test
();
}
catch
(
A
exception
)
{
try
{
try
{
throw
exception
;
// used to throw A, now throws Ab
}
catch
(
Ac
cException
)
{
// This should NOT catch sibling exception Ab
throw
new
RuntimeException
(
"FAIL: Should not be caught in catch Ac"
);
}
}
catch
(
Ab
|
Ac
bcException
)
{
if
(
bcException
instanceof
Ac
)
{
throw
new
RuntimeException
(
"FAIL: Sibling exception Ab not caught as expected"
);
}
else
if
(
bcException
instanceof
Ab
)
{
System
.
out
.
println
(
"PASS"
);
}
}
}
}
public
void
test
()
{
throw
new
Ab
();
}
static
class
A
extends
RuntimeException
{}
// Test class
static
class
Ab
extends
A
{}
// Test class
static
class
Ac
extends
A
{}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录