Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
63c90b76
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看板
提交
63c90b76
编写于
12月 13, 2013
作者:
M
mduigou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8029055: Map.merge implementations should refuse null value param
Reviewed-by: briangoetz, dl
上级
9805086f
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
31 addition
and
67 deletion
+31
-67
src/share/classes/java/util/HashMap.java
src/share/classes/java/util/HashMap.java
+2
-0
src/share/classes/java/util/Map.java
src/share/classes/java/util/Map.java
+26
-35
src/share/classes/java/util/concurrent/ConcurrentMap.java
src/share/classes/java/util/concurrent/ConcurrentMap.java
+3
-5
test/java/util/Map/Defaults.java
test/java/util/Map/Defaults.java
+0
-27
未找到文件。
src/share/classes/java/util/HashMap.java
浏览文件 @
63c90b76
...
...
@@ -1212,6 +1212,8 @@ public class HashMap<K,V> extends AbstractMap<K,V>
@Override
public
V
merge
(
K
key
,
V
value
,
BiFunction
<?
super
V
,
?
super
V
,
?
extends
V
>
remappingFunction
)
{
if
(
value
==
null
)
throw
new
NullPointerException
();
if
(
remappingFunction
==
null
)
throw
new
NullPointerException
();
int
hash
=
hash
(
key
);
...
...
src/share/classes/java/util/Map.java
浏览文件 @
63c90b76
...
...
@@ -600,7 +600,7 @@ public interface Map<K,V> {
* @implSpec
* The default implementation is equivalent to, for this {@code map}:
* <pre> {@code
* for (
(
Map.Entry<K, V> entry : map.entrySet())
* for (Map.Entry<K, V> entry : map.entrySet())
* action.accept(entry.getKey(), entry.getValue());
* }</pre>
*
...
...
@@ -640,7 +640,7 @@ public interface Map<K,V> {
* @implSpec
* <p>The default implementation is equivalent to, for this {@code map}:
* <pre> {@code
* for (
(
Map.Entry<K, V> entry : map.entrySet())
* for (Map.Entry<K, V> entry : map.entrySet())
* entry.setValue(function.apply(entry.getKey(), entry.getValue()));
* }</pre>
*
...
...
@@ -1110,8 +1110,8 @@ public interface Map<K,V> {
/**
* If the specified key is not already associated with a value or is
* associated with null, associates it with the given value.
* Otherwise, replaces the value with the results of the given
* associated with null, associates it with the given
non-null
value.
* Otherwise, replaces the
associated
value with the results of the given
* remapping function, or removes if the result is {@code null}. This
* method may be of use when combining multiple mapped values for a key.
* For example, to either create or append a {@code String msg} to a
...
...
@@ -1121,15 +1121,14 @@ public interface Map<K,V> {
* map.merge(key, msg, String::concat)
* }</pre>
*
* <p>If the function returns {@code null}, the mapping is removed (or
* remains absent if initially absent). If the function itself throws an
* (unchecked) exception, the exception is rethrown, and the current mapping
* is left unchanged.
* <p>If the function returns {@code null} the mapping is removed. If the
* function itself throws an (unchecked) exception, the exception is
* rethrown, and the current mapping is left unchanged.
*
* @implSpec
* The default implementation is equivalent to performing the
*
following steps for this {@code map}, then returning the
*
current value or
{@code null} if absent:
* The default implementation is equivalent to performing the
following
*
steps for this {@code map}, then returning the current value or
* {@code null} if absent:
*
* <pre> {@code
* V oldValue = map.get(key);
...
...
@@ -1137,8 +1136,6 @@ public interface Map<K,V> {
* remappingFunction.apply(oldValue, value);
* if (newValue == null)
* map.remove(key);
* else if (oldValue == null)
* map.remove(key);
* else
* map.put(key, newValue);
* }</pre>
...
...
@@ -1151,42 +1148,36 @@ public interface Map<K,V> {
* whether the function is applied once atomically only if the value is not
* present.
*
* @param key key with which the specified value is to be associated
* @param value the value to use if absent
* @param key key with which the resulting value is to be associated
* @param value the non-null value to be merged with the existing value
* associated with the key or, if no existing value or a null value
* is associated with the key, to be associated with the key
* @param remappingFunction the function to recompute a value if present
* @return the new value associated with the specified key, or null if none
* @return the new value associated with the specified key, or null if no
* value is associated with the key
* @throws UnsupportedOperationException if the {@code put} operation
* is not supported by this map
* (<a href="Collection.html#optional-restrictions">optional</a>)
* @throws ClassCastException if the class of the specified key or value
* prevents it from being stored in this map
* (<a href="Collection.html#optional-restrictions">optional</a>)
* @throws NullPointerException if the specified key is null and
*
this map does not support null keys, or the remappingFunction
*
is
null
* @throws NullPointerException if the specified key is null and
this map
*
does not support null keys or the value or remappingFunction is
* null
* @since 1.8
*/
default
V
merge
(
K
key
,
V
value
,
BiFunction
<?
super
V
,
?
super
V
,
?
extends
V
>
remappingFunction
)
{
Objects
.
requireNonNull
(
remappingFunction
);
Objects
.
requireNonNull
(
value
);
V
oldValue
=
get
(
key
);
if
(
oldValue
!=
null
)
{
V
newValue
=
remappingFunction
.
apply
(
oldValue
,
value
);
if
(
newValue
!=
null
)
{
put
(
key
,
newValue
);
return
newValue
;
}
else
{
remove
(
key
);
return
null
;
}
V
newValue
=
(
oldValue
==
null
)
?
value
:
remappingFunction
.
apply
(
oldValue
,
value
);
if
(
newValue
==
null
)
{
remove
(
key
);
}
else
{
if
(
value
==
null
)
{
remove
(
key
);
return
null
;
}
else
{
put
(
key
,
value
);
return
value
;
}
put
(
key
,
newValue
);
}
return
newValue
;
}
}
src/share/classes/java/util/concurrent/ConcurrentMap.java
浏览文件 @
63c90b76
...
...
@@ -463,9 +463,9 @@ public interface ConcurrentMap<K, V> extends Map<K, V> {
* {@inheritDoc}
*
* @implSpec
* The default implementation is equivalent to performing the
*
following steps for this {@code map}, then returning the
*
current value or
{@code null} if absent:
* The default implementation is equivalent to performing the
following
*
steps for this {@code map}, then returning the current value or
* {@code null} if absent:
*
* <pre> {@code
* V oldValue = map.get(key);
...
...
@@ -473,8 +473,6 @@ public interface ConcurrentMap<K, V> extends Map<K, V> {
* remappingFunction.apply(oldValue, value);
* if (newValue == null)
* map.remove(key);
* else if (oldValue == null)
* map.remove(key);
* else
* map.put(key, newValue);
* }</pre>
...
...
test/java/util/Map/Defaults.java
浏览文件 @
63c90b76
...
...
@@ -741,7 +741,6 @@ public class Defaults {
Collection
<
Object
[]>
cases
=
new
ArrayList
<>();
cases
.
addAll
(
makeMergeTestCases
());
cases
.
addAll
(
makeMergeNullValueTestCases
());
return
cases
.
iterator
();
}
...
...
@@ -764,32 +763,6 @@ public class Defaults {
return
cases
;
}
static
Collection
<
Object
[]>
makeMergeNullValueTestCases
()
{
Collection
<
Object
[]>
cases
=
new
ArrayList
<>();
for
(
Object
[]
mapParams
:
makeAllRWMapsWithNulls
()
)
{
cases
.
add
(
new
Object
[]
{
mapParams
[
0
],
mapParams
[
1
],
Merging
.
Value
.
OLDVALUE
,
Merging
.
Value
.
NULL
,
Merging
.
Merger
.
NULL
,
Merging
.
Value
.
ABSENT
,
Merging
.
Value
.
NULL
});
}
for
(
Object
[]
mapParams
:
makeAllRWMapsWithNulls
()
)
{
cases
.
add
(
new
Object
[]
{
mapParams
[
0
],
mapParams
[
1
],
Merging
.
Value
.
OLDVALUE
,
Merging
.
Value
.
NULL
,
Merging
.
Merger
.
RESULT
,
Merging
.
Value
.
RESULT
,
Merging
.
Value
.
RESULT
});
}
for
(
Object
[]
mapParams
:
makeAllRWMapsWithNulls
()
)
{
cases
.
add
(
new
Object
[]
{
mapParams
[
0
],
mapParams
[
1
],
Merging
.
Value
.
ABSENT
,
Merging
.
Value
.
NULL
,
Merging
.
Merger
.
UNUSED
,
Merging
.
Value
.
ABSENT
,
Merging
.
Value
.
NULL
});
}
for
(
Object
[]
mapParams
:
makeAllRWMapsWithNulls
()
)
{
cases
.
add
(
new
Object
[]
{
mapParams
[
0
],
mapParams
[
1
],
Merging
.
Value
.
NULL
,
Merging
.
Value
.
NULL
,
Merging
.
Merger
.
UNUSED
,
Merging
.
Value
.
ABSENT
,
Merging
.
Value
.
NULL
});
}
for
(
Object
[]
mapParams
:
makeAllRWMapsWithNulls
()
)
{
cases
.
add
(
new
Object
[]
{
mapParams
[
0
],
mapParams
[
1
],
Merging
.
Value
.
NULL
,
Merging
.
Value
.
NEWVALUE
,
Merging
.
Merger
.
UNUSED
,
Merging
.
Value
.
NEWVALUE
,
Merging
.
Value
.
NEWVALUE
});
}
return
cases
;
}
public
interface
Thrower
<
T
extends
Throwable
>
{
public
void
run
()
throws
T
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录