Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
8e1415df
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看板
提交
8e1415df
编写于
6月 27, 2014
作者:
M
mduigou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8048207: Collections.checkedQueue.offer() calls add on wrapped queue
Reviewed-by: psandoz
上级
9ec8f5cc
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
45 addition
and
94 deletion
+45
-94
src/share/classes/java/util/Collections.java
src/share/classes/java/util/Collections.java
+6
-17
test/java/util/Collections/CheckedQueue.java
test/java/util/Collections/CheckedQueue.java
+39
-77
未找到文件。
src/share/classes/java/util/Collections.java
浏览文件 @
8e1415df
...
...
@@ -3077,10 +3077,7 @@ public class Collections {
public
void
remove
()
{
it
.
remove
();
}};
}
public
boolean
add
(
E
e
)
{
typeCheck
(
e
);
return
c
.
add
(
e
);
}
public
boolean
add
(
E
e
)
{
return
c
.
add
(
typeCheck
(
e
));
}
private
E
[]
zeroLengthElementArray
;
// Lazily initialized
...
...
@@ -3187,11 +3184,7 @@ public class Collections {
public
E
peek
()
{
return
queue
.
peek
();}
public
E
poll
()
{
return
queue
.
poll
();}
public
E
remove
()
{
return
queue
.
remove
();}
public
boolean
offer
(
E
e
)
{
typeCheck
(
e
);
return
add
(
e
);
}
public
boolean
offer
(
E
e
)
{
return
queue
.
offer
(
typeCheck
(
e
));}
}
/**
...
...
@@ -3440,13 +3433,11 @@ public class Collections {
public
int
lastIndexOf
(
Object
o
)
{
return
list
.
lastIndexOf
(
o
);
}
public
E
set
(
int
index
,
E
element
)
{
typeCheck
(
element
);
return
list
.
set
(
index
,
element
);
return
list
.
set
(
index
,
typeCheck
(
element
));
}
public
void
add
(
int
index
,
E
element
)
{
typeCheck
(
element
);
list
.
add
(
index
,
element
);
list
.
add
(
index
,
typeCheck
(
element
));
}
public
boolean
addAll
(
int
index
,
Collection
<?
extends
E
>
c
)
{
...
...
@@ -3467,13 +3458,11 @@ public class Collections {
public
void
remove
()
{
i
.
remove
();
}
public
void
set
(
E
e
)
{
typeCheck
(
e
);
i
.
set
(
e
);
i
.
set
(
typeCheck
(
e
));
}
public
void
add
(
E
e
)
{
typeCheck
(
e
);
i
.
add
(
e
);
i
.
add
(
typeCheck
(
e
));
}
@Override
...
...
test/java/util/Collections/CheckedQueue.java
浏览文件 @
8e1415df
/*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011,
2014,
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
...
...
@@ -23,55 +23,40 @@
/*
* @test
* @bug 5020931
* @bug 5020931
8048207
* @summary Unit test for Collections.checkedQueue
* @run testng CheckedQueue
*/
import
java.lang.reflect.Method
;
import
java.util.Collections
;
import
java.util.Iterator
;
import
java.util.Queue
;
import
java.util.concurrent.ArrayBlockingQueue
;
public
class
CheckedQueue
{
static
int
status
=
0
;
public
static
void
main
(
String
[]
args
)
throws
Exception
{
new
CheckedQueue
();
}
import
org.testng.annotations.Test
;
import
static
org
.
testng
.
Assert
.
fail
;
import
static
org
.
testng
.
Assert
.
assertEquals
;
import
static
org
.
testng
.
Assert
.
assertTrue
;
import
static
org
.
testng
.
Assert
.
assertFalse
;
public
CheckedQueue
()
throws
Exception
{
run
();
}
private
void
run
()
throws
Exception
{
Method
[]
methods
=
this
.
getClass
().
getDeclaredMethods
();
for
(
int
i
=
0
;
i
<
methods
.
length
;
i
++)
{
Method
method
=
methods
[
i
];
String
methodName
=
method
.
getName
();
if
(
methodName
.
startsWith
(
"test"
))
{
try
{
Object
obj
=
method
.
invoke
(
this
,
new
Object
[
0
]);
}
catch
(
Exception
e
)
{
throw
new
Exception
(
this
.
getClass
().
getName
()
+
"."
+
methodName
+
" test failed, test exception "
+
"follows\n"
+
e
.
getCause
());
}
}
}
}
public
class
CheckedQueue
{
/**
* This test adds items to a queue.
*/
private
void
test00
()
{
@Test
public
void
testAdd
()
{
int
arrayLength
=
10
;
ArrayBlockingQueue
<
String
>
abq
=
new
ArrayBlockingQueue
(
arrayLength
);
Queue
<
String
>
abq
=
Collections
.
checkedQueue
(
new
ArrayBlockingQueue
<>(
arrayLength
),
String
.
class
);
for
(
int
i
=
0
;
i
<
arrayLength
;
i
++)
{
abq
.
add
(
new
String
(
Integer
.
toString
(
i
)));
abq
.
add
(
Integer
.
toString
(
i
));
}
try
{
abq
.
add
(
"full"
);
}
catch
(
IllegalStateException
full
)
{
}
}
...
...
@@ -80,23 +65,17 @@ public class CheckedQueue {
* {@code String}s gets the checked queue, and attempt to add an Integer to
* the checked queue.
*/
private
void
test01
()
throws
Exception
{
@Test
(
expectedExceptions
=
ClassCastException
.
class
)
public
void
testAddFail1
()
{
int
arrayLength
=
10
;
ArrayBlockingQueue
<
String
>
abq
=
new
ArrayBlockingQueue
(
arrayLength
+
1
);
for
(
int
i
=
0
;
i
<
arrayLength
;
i
++)
{
abq
.
add
(
new
String
(
Integer
.
toString
(
i
)
));
abq
.
add
(
Integer
.
toString
(
i
));
}
Queue
q
=
Collections
.
checkedQueue
(
abq
,
String
.
class
);
try
{
q
.
add
(
new
Integer
(
0
));
throw
new
Exception
(
this
.
getClass
().
getName
()
+
"."
+
"test01 test"
+
" failed, should throw ClassCastException."
);
}
catch
(
ClassCastException
cce
)
{
// Do nothing.
}
q
.
add
(
0
);
}
/**
...
...
@@ -104,47 +83,40 @@ public class CheckedQueue {
* {@code String}, gets the checked queue, and attempt to add an Integer to
* the checked queue.
*/
private
void
test02
()
throws
Exception
{
@Test
(
expectedExceptions
=
ClassCastException
.
class
)
public
void
testAddFail2
()
{
ArrayBlockingQueue
<
String
>
abq
=
new
ArrayBlockingQueue
(
1
);
Queue
q
=
Collections
.
checkedQueue
(
abq
,
String
.
class
);
try
{
q
.
add
(
new
Integer
(
0
));
throw
new
Exception
(
this
.
getClass
().
getName
()
+
"."
+
"test02 test"
+
" failed, should throw ClassCastException."
);
}
catch
(
ClassCastException
e
)
{
// Do nothing.
}
q
.
add
(
0
);
}
/**
* This test tests the Collections.checkedQueue method call for nulls in
* each and both of the parameters.
*/
private
void
test03
()
throws
Exception
{
@Test
public
void
testArgs
()
{
ArrayBlockingQueue
<
String
>
abq
=
new
ArrayBlockingQueue
(
1
);
Queue
q
;
try
{
q
=
Collections
.
checkedQueue
(
null
,
String
.
class
);
throw
new
Exception
(
this
.
getClass
().
getName
()
+
"."
+
"test03 test"
+
" failed, should throw NullPointerException."
);
fail
(
"should throw NullPointerException."
);
}
catch
(
NullPointerException
npe
)
{
// Do nothing
}
try
{
q
=
Collections
.
checkedQueue
(
abq
,
null
);
throw
new
Exception
(
this
.
getClass
().
getName
()
+
"."
+
"test03 test"
+
" failed, should throw NullPointerException."
);
fail
(
"should throw NullPointerException."
);
}
catch
(
Exception
e
)
{
// Do nothing
}
try
{
q
=
Collections
.
checkedQueue
(
null
,
null
);
throw
new
Exception
(
this
.
getClass
().
getName
()
+
"."
+
"test03 test"
+
" failed, should throw NullPointerException."
);
fail
(
"should throw NullPointerException."
);
}
catch
(
Exception
e
)
{
// Do nothing
}
...
...
@@ -153,38 +125,28 @@ public class CheckedQueue {
/**
* This test tests the CheckedQueue.offer method.
*/
private
void
test04
()
throws
Exception
{
@Test
public
void
testOffer
()
{
ArrayBlockingQueue
<
String
>
abq
=
new
ArrayBlockingQueue
(
1
);
Queue
q
=
Collections
.
checkedQueue
(
abq
,
String
.
class
);
try
{
q
.
offer
(
null
);
throw
new
Exception
(
this
.
getClass
().
getName
()
+
"."
+
"test04 test"
+
" failed, should throw NullPointerException."
);
fail
(
"should throw NullPointerException."
);
}
catch
(
NullPointerException
npe
)
{
// Do nothing
}
try
{
q
.
offer
(
new
Integer
(
0
));
throw
new
Exception
(
this
.
getClass
().
getName
()
+
"."
+
"test04 test"
+
" failed, should throw ClassCastException."
);
q
.
offer
(
0
);
fail
(
"should throw ClassCastException."
);
}
catch
(
ClassCastException
cce
)
{
// Do nothing
}
q
.
offer
(
new
String
(
"0"
));
try
{
q
.
offer
(
new
String
(
"1"
));
throw
new
Exception
(
this
.
getClass
().
getName
()
+
"."
+
"test04 test"
+
" failed, should throw IllegalStateException."
);
}
catch
(
IllegalStateException
ise
)
{
// Do nothing
}
}
private
void
test05
()
{
assertTrue
(
q
.
offer
(
"0"
),
"queue should have room"
);
// no room at the inn!
assertFalse
(
q
.
offer
(
"1"
),
"queue should be full"
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录