Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
ab15ed2a
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ab15ed2a
编写于
1月 15, 2014
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ObjectUtils.isCompatibleWithThrowsClause supports varargs now
上级
feb9d261
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
17 addition
and
19 deletion
+17
-19
spring-core/src/main/java/org/springframework/util/ObjectUtils.java
...e/src/main/java/org/springframework/util/ObjectUtils.java
+7
-9
spring-core/src/test/java/org/springframework/util/ObjectUtilsTests.java
.../test/java/org/springframework/util/ObjectUtilsTests.java
+10
-10
未找到文件。
spring-core/src/main/java/org/springframework/util/ObjectUtils.java
浏览文件 @
ab15ed2a
...
...
@@ -59,23 +59,21 @@ public abstract class ObjectUtils {
}
/**
* Check whether the given exception is compatible with the
exceptions
* declared in a throws clause.
* @param ex the exception to check
ed
* @param declaredExceptions the exceptions declared in the throws clause
* Check whether the given exception is compatible with the
specified
*
exception types, as
declared in a throws clause.
* @param ex the exception to check
* @param declaredExceptions the exception
type
s declared in the throws clause
* @return whether the given exception is compatible
*/
public
static
boolean
isCompatibleWithThrowsClause
(
Throwable
ex
,
Class
<?>
[]
declaredExceptions
)
{
public
static
boolean
isCompatibleWithThrowsClause
(
Throwable
ex
,
Class
<?>
...
declaredExceptions
)
{
if
(!
isCheckedException
(
ex
))
{
return
true
;
}
if
(
declaredExceptions
!=
null
)
{
int
i
=
0
;
while
(
i
<
declaredExceptions
.
length
)
{
if
(
declaredExceptions
[
i
].
isAssignableFrom
(
ex
.
getClass
()))
{
for
(
Class
<?>
declaredException
:
declaredExceptions
)
{
if
(
declaredException
.
isInstance
(
ex
))
{
return
true
;
}
i
++;
}
}
return
false
;
...
...
spring-core/src/test/java/org/springframework/util/ObjectUtilsTests.java
浏览文件 @
ab15ed2a
/*
* Copyright 2002-20
06
the original author or authors.
* Copyright 2002-20
13
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -16,9 +16,6 @@
package
org.springframework.util
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
java.io.IOException
;
import
java.sql.SQLException
;
...
...
@@ -26,6 +23,9 @@ import junit.framework.TestCase;
import
org.springframework.core.task.TaskRejectedException
;
import
static
org
.
hamcrest
.
CoreMatchers
.*;
import
static
org
.
junit
.
Assert
.*;
/**
* @author Rod Johnson
* @author Juergen Hoeller
...
...
@@ -51,25 +51,25 @@ public final class ObjectUtilsTests extends TestCase {
Class
<?>[]
sqlAndIO
=
new
Class
[]
{
SQLException
.
class
,
IOException
.
class
};
Class
<?>[]
throwable
=
new
Class
[]
{
Throwable
.
class
};
assertTrue
(
ObjectUtils
.
isCompatibleWithThrowsClause
(
new
RuntimeException
()
,
null
));
assertTrue
(
ObjectUtils
.
isCompatibleWithThrowsClause
(
new
RuntimeException
()));
assertTrue
(
ObjectUtils
.
isCompatibleWithThrowsClause
(
new
RuntimeException
(),
empty
));
assertTrue
(
ObjectUtils
.
isCompatibleWithThrowsClause
(
new
RuntimeException
(),
exception
));
assertTrue
(
ObjectUtils
.
isCompatibleWithThrowsClause
(
new
RuntimeException
(),
sqlAndIO
));
assertTrue
(
ObjectUtils
.
isCompatibleWithThrowsClause
(
new
RuntimeException
(),
throwable
));
assertFalse
(
ObjectUtils
.
isCompatibleWithThrowsClause
(
new
Exception
()
,
null
));
assertFalse
(
ObjectUtils
.
isCompatibleWithThrowsClause
(
new
Exception
()));
assertFalse
(
ObjectUtils
.
isCompatibleWithThrowsClause
(
new
Exception
(),
empty
));
assertTrue
(
ObjectUtils
.
isCompatibleWithThrowsClause
(
new
Exception
(),
exception
));
assertFalse
(
ObjectUtils
.
isCompatibleWithThrowsClause
(
new
Exception
(),
sqlAndIO
));
assertTrue
(
ObjectUtils
.
isCompatibleWithThrowsClause
(
new
Exception
(),
throwable
));
assertFalse
(
ObjectUtils
.
isCompatibleWithThrowsClause
(
new
SQLException
()
,
null
));
assertFalse
(
ObjectUtils
.
isCompatibleWithThrowsClause
(
new
SQLException
()));
assertFalse
(
ObjectUtils
.
isCompatibleWithThrowsClause
(
new
SQLException
(),
empty
));
assertTrue
(
ObjectUtils
.
isCompatibleWithThrowsClause
(
new
SQLException
(),
exception
));
assertTrue
(
ObjectUtils
.
isCompatibleWithThrowsClause
(
new
SQLException
(),
sqlAndIO
));
assertTrue
(
ObjectUtils
.
isCompatibleWithThrowsClause
(
new
SQLException
(),
throwable
));
assertFalse
(
ObjectUtils
.
isCompatibleWithThrowsClause
(
new
Throwable
()
,
null
));
assertFalse
(
ObjectUtils
.
isCompatibleWithThrowsClause
(
new
Throwable
()));
assertFalse
(
ObjectUtils
.
isCompatibleWithThrowsClause
(
new
Throwable
(),
empty
));
assertFalse
(
ObjectUtils
.
isCompatibleWithThrowsClause
(
new
Throwable
(),
exception
));
assertFalse
(
ObjectUtils
.
isCompatibleWithThrowsClause
(
new
Throwable
(),
sqlAndIO
));
...
...
@@ -196,7 +196,7 @@ public final class ObjectUtilsTests extends TestCase {
Object
obj
=
new
Object
();
String
expected
=
obj
.
getClass
().
getName
()
+
"@"
+
ObjectUtils
.
getIdentityHexString
(
obj
);
String
actual
=
ObjectUtils
.
identityToString
(
obj
);
assertEquals
(
expected
.
toString
()
,
actual
);
assertEquals
(
expected
,
actual
);
}
public
void
testIdentityToStringWithNullObject
()
{
...
...
@@ -620,7 +620,7 @@ public final class ObjectUtilsTests extends TestCase {
assertEquals
(
"null"
,
ObjectUtils
.
nullSafeToString
((
String
[])
null
));
}
enum
Tropes
{
FOO
,
BAR
,
baz
}
;
enum
Tropes
{
FOO
,
BAR
,
baz
}
public
void
testContainsConstant
()
{
assertThat
(
ObjectUtils
.
containsConstant
(
Tropes
.
values
(),
"FOO"
),
is
(
true
));
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录