Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
45af944f
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
45af944f
编写于
5月 16, 2013
作者:
M
mchung
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
4487672: (proxy) Proxy constructor should check for null argument
Reviewed-by: alanb, lancea
上级
adbcdc0d
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
32 addition
and
17 deletion
+32
-17
src/share/classes/java/lang/reflect/Proxy.java
src/share/classes/java/lang/reflect/Proxy.java
+7
-4
test/java/lang/reflect/Proxy/Basic1.java
test/java/lang/reflect/Proxy/Basic1.java
+25
-13
未找到文件。
src/share/classes/java/lang/reflect/Proxy.java
浏览文件 @
45af944f
...
@@ -31,6 +31,7 @@ import java.security.PrivilegedAction;
...
@@ -31,6 +31,7 @@ import java.security.PrivilegedAction;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
java.util.IdentityHashMap
;
import
java.util.IdentityHashMap
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Objects
;
import
java.util.concurrent.atomic.AtomicLong
;
import
java.util.concurrent.atomic.AtomicLong
;
import
java.util.function.BiFunction
;
import
java.util.function.BiFunction
;
import
sun.misc.ProxyGenerator
;
import
sun.misc.ProxyGenerator
;
...
@@ -255,9 +256,13 @@ public class Proxy implements java.io.Serializable {
...
@@ -255,9 +256,13 @@ public class Proxy implements java.io.Serializable {
* (typically, a dynamic proxy class) with the specified value
* (typically, a dynamic proxy class) with the specified value
* for its invocation handler.
* for its invocation handler.
*
*
* @param h the invocation handler for this proxy instance
* @param h the invocation handler for this proxy instance
*
* @throws NullPointerException if the given invocation handler, {@code h},
* is {@code null}.
*/
*/
protected
Proxy
(
InvocationHandler
h
)
{
protected
Proxy
(
InvocationHandler
h
)
{
Objects
.
requireNonNull
(
h
);
this
.
h
=
h
;
this
.
h
=
h
;
}
}
...
@@ -698,9 +703,7 @@ public class Proxy implements java.io.Serializable {
...
@@ -698,9 +703,7 @@ public class Proxy implements java.io.Serializable {
InvocationHandler
h
)
InvocationHandler
h
)
throws
IllegalArgumentException
throws
IllegalArgumentException
{
{
if
(
h
==
null
)
{
Objects
.
requireNonNull
(
h
);
throw
new
NullPointerException
();
}
final
SecurityManager
sm
=
System
.
getSecurityManager
();
final
SecurityManager
sm
=
System
.
getSecurityManager
();
if
(
sm
!=
null
)
{
if
(
sm
!=
null
)
{
...
...
test/java/lang/reflect/Proxy/Basic1.java
浏览文件 @
45af944f
...
@@ -22,7 +22,7 @@
...
@@ -22,7 +22,7 @@
*/
*/
/* @test
/* @test
* @bug 4227192
* @bug 4227192
4487672
* @summary This is a basic functional test of the dynamic proxy API (part 1).
* @summary This is a basic functional test of the dynamic proxy API (part 1).
* @author Peter Jones
* @author Peter Jones
*
*
...
@@ -42,15 +42,15 @@ public class Basic1 {
...
@@ -42,15 +42,15 @@ public class Basic1 {
"\nBasic functional test of dynamic proxy API, part 1\n"
);
"\nBasic functional test of dynamic proxy API, part 1\n"
);
try
{
try
{
Class
[]
interfaces
=
Class
<?>
[]
interfaces
=
new
Class
[]
{
Runnable
.
class
,
Observer
.
class
};
new
Class
<?>
[]
{
Runnable
.
class
,
Observer
.
class
};
ClassLoader
loader
=
ClassLoader
.
getSystemClassLoader
();
ClassLoader
loader
=
ClassLoader
.
getSystemClassLoader
();
/*
/*
* Generate a proxy class.
* Generate a proxy class.
*/
*/
Class
proxyClass
=
Proxy
.
getProxyClass
(
loader
,
interfaces
);
Class
<?>
proxyClass
=
Proxy
.
getProxyClass
(
loader
,
interfaces
);
System
.
err
.
println
(
"+ generated proxy class: "
+
proxyClass
);
System
.
err
.
println
(
"+ generated proxy class: "
+
proxyClass
);
/*
/*
...
@@ -72,19 +72,19 @@ public class Basic1 {
...
@@ -72,19 +72,19 @@ public class Basic1 {
/*
/*
* Verify that it is assignable to the proxy interfaces.
* Verify that it is assignable to the proxy interfaces.
*/
*/
for
(
int
i
=
0
;
i
<
interfaces
.
length
;
i
++
)
{
for
(
Class
<?>
intf
:
interfaces
)
{
if
(!
int
erfaces
[
i
]
.
isAssignableFrom
(
proxyClass
))
{
if
(!
int
f
.
isAssignableFrom
(
proxyClass
))
{
throw
new
RuntimeException
(
throw
new
RuntimeException
(
"proxy class not assignable to proxy interface "
+
"proxy class not assignable to proxy interface "
+
int
erfaces
[
i
]
.
getName
());
int
f
.
getName
());
}
}
}
}
/*
/*
* Verify that it has the given permutation of interfaces.
* Verify that it has the given permutation of interfaces.
*/
*/
List
l1
=
Arrays
.
asList
(
interfaces
);
List
<
Class
<?>>
l1
=
Arrays
.
asList
(
interfaces
);
List
l2
=
Arrays
.
asList
(
proxyClass
.
getInterfaces
());
List
<
Class
<?>>
l2
=
Arrays
.
asList
(
proxyClass
.
getInterfaces
());
System
.
err
.
println
(
"+ proxy class's interfaces: "
+
l2
);
System
.
err
.
println
(
"+ proxy class's interfaces: "
+
l2
);
if
(!
l1
.
equals
(
l2
))
{
if
(!
l1
.
equals
(
l2
))
{
throw
new
RuntimeException
(
throw
new
RuntimeException
(
...
@@ -118,14 +118,26 @@ public class Basic1 {
...
@@ -118,14 +118,26 @@ public class Basic1 {
* Verify that it has a constructor that takes an
* Verify that it has a constructor that takes an
* InvocationHandler instance.
* InvocationHandler instance.
*/
*/
Constructor
cons
=
proxyClass
.
getConstructor
(
Constructor
<?>
cons
=
proxyClass
.
getConstructor
(
InvocationHandler
.
class
);
new
Class
[]
{
InvocationHandler
.
class
});
/*
* Test constructor with null InvocationHandler
*/
try
{
cons
.
newInstance
(
new
Object
[]
{
null
});
throw
new
RuntimeException
(
"Expected NullPointerException thrown"
);
}
catch
(
InvocationTargetException
e
)
{
Throwable
t
=
e
.
getTargetException
();
if
(!(
t
instanceof
NullPointerException
))
{
throw
t
;
}
}
/*
/*
* Construct a proxy instance.
* Construct a proxy instance.
*/
*/
Handler
handler
=
new
Handler
();
Handler
handler
=
new
Handler
();
Object
proxy
=
cons
.
newInstance
(
new
Object
[]
{
handler
}
);
Object
proxy
=
cons
.
newInstance
(
handler
);
handler
.
currentProxy
=
proxy
;
handler
.
currentProxy
=
proxy
;
/*
/*
...
@@ -141,7 +153,7 @@ public class Basic1 {
...
@@ -141,7 +153,7 @@ public class Basic1 {
System
.
err
.
println
(
"\nTEST PASSED"
);
System
.
err
.
println
(
"\nTEST PASSED"
);
}
catch
(
Exception
e
)
{
}
catch
(
Throwable
e
)
{
System
.
err
.
println
(
"\nTEST FAILED:"
);
System
.
err
.
println
(
"\nTEST FAILED:"
);
e
.
printStackTrace
();
e
.
printStackTrace
();
throw
new
RuntimeException
(
"TEST FAILED: "
+
e
.
toString
());
throw
new
RuntimeException
(
"TEST FAILED: "
+
e
.
toString
());
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录