Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
aabc7a22
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看板
提交
aabc7a22
编写于
4月 06, 2011
作者:
A
alanb
浏览文件
操作
浏览文件
下载
差异文件
Merge
上级
36cde02e
a1940341
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
570 addition
and
111 deletion
+570
-111
src/share/classes/java/util/EnumMap.java
src/share/classes/java/util/EnumMap.java
+119
-57
src/share/classes/java/util/IdentityHashMap.java
src/share/classes/java/util/IdentityHashMap.java
+61
-50
test/java/util/EnumMap/DistinctEntrySetElements.java
test/java/util/EnumMap/DistinctEntrySetElements.java
+60
-0
test/java/util/EnumMap/EntrySetIteratorRemoveInvalidatesEntry.java
.../util/EnumMap/EntrySetIteratorRemoveInvalidatesEntry.java
+60
-0
test/java/util/EnumMap/SimpleSerialization.java
test/java/util/EnumMap/SimpleSerialization.java
+89
-0
test/java/util/IdentityHashMap/DistinctEntrySetElements.java
test/java/util/IdentityHashMap/DistinctEntrySetElements.java
+61
-0
test/java/util/IdentityHashMap/EntrySetIteratorRemoveInvalidatesEntry.java
...entityHashMap/EntrySetIteratorRemoveInvalidatesEntry.java
+59
-0
test/java/util/ResourceBundle/Bug4168625Test.java
test/java/util/ResourceBundle/Bug4168625Test.java
+2
-4
test/java/util/concurrent/ConcurrentHashMap/DistinctEntrySetElements.java
...oncurrent/ConcurrentHashMap/DistinctEntrySetElements.java
+59
-0
未找到文件。
src/share/classes/java/util/EnumMap.java
浏览文件 @
aabc7a22
...
...
@@ -106,7 +106,7 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V>
/**
* Distinguished non-null value for representing null values.
*/
private
static
final
Object
NULL
=
new
Object
(
);
private
static
final
Object
NULL
=
new
Integer
(
0
);
private
Object
maskNull
(
Object
value
)
{
return
(
value
==
null
?
NULL
:
value
);
...
...
@@ -116,7 +116,7 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V>
return
(
V
)
(
value
==
NULL
?
null
:
value
);
}
private
static
Enum
[]
ZERO_LENGTH_ENUM_ARRAY
=
new
Enum
[
0
];
private
static
final
Enum
[]
ZERO_LENGTH_ENUM_ARRAY
=
new
Enum
[
0
];
/**
* Creates an empty enum map with the specified key type.
...
...
@@ -464,6 +464,7 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V>
public
Iterator
<
Map
.
Entry
<
K
,
V
>>
iterator
()
{
return
new
EntryIterator
();
}
public
boolean
contains
(
Object
o
)
{
if
(!(
o
instanceof
Map
.
Entry
))
return
false
;
...
...
@@ -552,70 +553,82 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V>
}
}
/**
* Since we don't use Entry objects, we use the Iterator itself as entry.
*/
private
class
EntryIterator
extends
EnumMapIterator
<
Map
.
Entry
<
K
,
V
>>
implements
Map
.
Entry
<
K
,
V
>
{
private
class
EntryIterator
extends
EnumMapIterator
<
Map
.
Entry
<
K
,
V
>>
{
private
Entry
lastReturnedEntry
=
null
;
public
Map
.
Entry
<
K
,
V
>
next
()
{
if
(!
hasNext
())
throw
new
NoSuchElementException
();
lastReturned
Index
=
index
++
;
return
this
;
lastReturned
Entry
=
new
Entry
(
index
++)
;
return
lastReturnedEntry
;
}
public
K
getKey
()
{
checkLastReturnedIndexForEntryUse
();
return
keyUniverse
[
lastReturnedIndex
];
public
void
remove
()
{
lastReturnedIndex
=
((
null
==
lastReturnedEntry
)
?
-
1
:
lastReturnedEntry
.
index
);
super
.
remove
();
lastReturnedEntry
.
index
=
lastReturnedIndex
;
lastReturnedEntry
=
null
;
}
public
V
getValue
()
{
checkLastReturnedIndexForEntryUse
();
return
unmaskNull
(
vals
[
lastReturnedIndex
]);
}
private
class
Entry
implements
Map
.
Entry
<
K
,
V
>
{
private
int
index
;
public
V
setValue
(
V
value
)
{
checkLastReturnedIndexForEntryUse
();
V
oldValue
=
unmaskNull
(
vals
[
lastReturnedIndex
]);
vals
[
lastReturnedIndex
]
=
maskNull
(
value
);
return
oldValue
;
}
private
Entry
(
int
index
)
{
this
.
index
=
index
;
}
public
boolean
equals
(
Object
o
)
{
if
(
lastReturnedIndex
<
0
)
return
o
==
this
;
public
K
getKey
()
{
checkIndexForEntryUse
();
return
keyUniverse
[
index
];
}
if
(!(
o
instanceof
Map
.
Entry
))
return
false
;
Map
.
Entry
e
=
(
Map
.
Entry
)
o
;
V
ourValue
=
unmaskNull
(
vals
[
lastReturnedIndex
]);
Object
hisValue
=
e
.
getValue
();
return
e
.
getKey
()
==
keyUniverse
[
lastReturnedIndex
]
&&
(
ourValue
==
hisValue
||
(
ourValue
!=
null
&&
ourValue
.
equals
(
hisValue
)));
}
public
V
getValue
()
{
checkIndexForEntryUse
();
return
unmaskNull
(
vals
[
index
]);
}
public
int
hashCode
()
{
if
(
lastReturnedIndex
<
0
)
return
super
.
hashCode
();
public
V
setValue
(
V
value
)
{
checkIndexForEntryUse
();
V
oldValue
=
unmaskNull
(
vals
[
index
]);
vals
[
index
]
=
maskNull
(
value
);
return
oldValue
;
}
Object
value
=
vals
[
lastReturnedIndex
];
return
keyUniverse
[
lastReturnedIndex
].
hashCode
()
^
(
value
==
NULL
?
0
:
value
.
hashCode
());
}
public
boolean
equals
(
Object
o
)
{
if
(
index
<
0
)
return
o
==
this
;
public
String
toString
()
{
if
(
lastReturnedIndex
<
0
)
return
super
.
toString
();
if
(!(
o
instanceof
Map
.
Entry
))
return
false
;
return
keyUniverse
[
lastReturnedIndex
]
+
"="
+
unmaskNull
(
vals
[
lastReturnedIndex
]);
}
Map
.
Entry
e
=
(
Map
.
Entry
)
o
;
V
ourValue
=
unmaskNull
(
vals
[
index
]);
Object
hisValue
=
e
.
getValue
();
return
(
e
.
getKey
()
==
keyUniverse
[
index
]
&&
(
ourValue
==
hisValue
||
(
ourValue
!=
null
&&
ourValue
.
equals
(
hisValue
))));
}
private
void
checkLastReturnedIndexForEntryUse
()
{
if
(
lastReturnedIndex
<
0
)
throw
new
IllegalStateException
(
"Entry was removed"
);
public
int
hashCode
()
{
if
(
index
<
0
)
return
super
.
hashCode
();
return
entryHashCode
(
index
);
}
public
String
toString
()
{
if
(
index
<
0
)
return
super
.
toString
();
return
keyUniverse
[
index
]
+
"="
+
unmaskNull
(
vals
[
index
]);
}
private
void
checkIndexForEntryUse
()
{
if
(
index
<
0
)
throw
new
IllegalStateException
(
"Entry was removed"
);
}
}
}
...
...
@@ -631,10 +644,35 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V>
* @return <tt>true</tt> if the specified object is equal to this map
*/
public
boolean
equals
(
Object
o
)
{
if
(!(
o
instanceof
EnumMap
))
return
super
.
equals
(
o
);
if
(
this
==
o
)
return
true
;
if
(
o
instanceof
EnumMap
)
return
equals
((
EnumMap
)
o
);
if
(!(
o
instanceof
Map
))
return
false
;
Map
<
K
,
V
>
m
=
(
Map
<
K
,
V
>)
o
;
if
(
size
!=
m
.
size
())
return
false
;
for
(
int
i
=
0
;
i
<
keyUniverse
.
length
;
i
++)
{
if
(
null
!=
vals
[
i
])
{
K
key
=
keyUniverse
[
i
];
V
value
=
unmaskNull
(
vals
[
i
]);
if
(
null
==
value
)
{
if
(!((
null
==
m
.
get
(
key
))
&&
m
.
containsKey
(
key
)))
return
false
;
}
else
{
if
(!
value
.
equals
(
m
.
get
(
key
)))
return
false
;
}
}
}
return
true
;
}
EnumMap
em
=
(
EnumMap
)
o
;
private
boolean
equals
(
EnumMap
em
)
{
if
(
em
.
keyType
!=
keyType
)
return
size
==
0
&&
em
.
size
==
0
;
...
...
@@ -649,6 +687,26 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V>
return
true
;
}
/**
* Returns the hash code value for this map. The hash code of a map is
* defined to be the sum of the hash codes of each entry in the map.
*/
public
int
hashCode
()
{
int
h
=
0
;
for
(
int
i
=
0
;
i
<
keyUniverse
.
length
;
i
++)
{
if
(
null
!=
vals
[
i
])
{
h
+=
entryHashCode
(
i
);
}
}
return
h
;
}
private
int
entryHashCode
(
int
index
)
{
return
(
keyUniverse
[
index
].
hashCode
()
^
vals
[
index
].
hashCode
());
}
/**
* Returns a shallow copy of this enum map. (The values themselves
* are not cloned.
...
...
@@ -705,9 +763,13 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V>
s
.
writeInt
(
size
);
// Write out keys and values (alternating)
for
(
Map
.
Entry
<
K
,
V
>
e
:
entrySet
())
{
s
.
writeObject
(
e
.
getKey
());
s
.
writeObject
(
e
.
getValue
());
int
entriesToBeWritten
=
size
;
for
(
int
i
=
0
;
entriesToBeWritten
>
0
;
i
++)
{
if
(
null
!=
vals
[
i
])
{
s
.
writeObject
(
keyUniverse
[
i
]);
s
.
writeObject
(
unmaskNull
(
vals
[
i
]));
entriesToBeWritten
--;
}
}
}
...
...
src/share/classes/java/util/IdentityHashMap.java
浏览文件 @
aabc7a22
/*
* Copyright (c) 2000, 20
08
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 20
11
, 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
...
...
@@ -829,71 +829,82 @@ public class IdentityHashMap<K,V>
}
}
/**
* Since we don't use Entry objects, we use the Iterator
* itself as an entry.
*/
private
class
EntryIterator
extends
IdentityHashMapIterator
<
Map
.
Entry
<
K
,
V
>>
implements
Map
.
Entry
<
K
,
V
>
{
private
Entry
lastReturnedEntry
=
null
;
public
Map
.
Entry
<
K
,
V
>
next
()
{
nextIndex
(
);
return
this
;
lastReturnedEntry
=
new
Entry
(
nextIndex
()
);
return
lastReturnedEntry
;
}
public
K
getKey
()
{
// Provide a better exception than out of bounds index
if
(
lastReturnedIndex
<
0
)
throw
new
IllegalStateException
(
"Entry was removed"
);
return
(
K
)
unmaskNull
(
traversalTable
[
lastReturnedIndex
])
;
public
void
remove
()
{
lastReturnedIndex
=
((
null
==
lastReturnedEntry
)
?
-
1
:
lastReturnedEntry
.
index
);
super
.
remove
(
);
lastReturnedEntry
.
index
=
lastReturnedIndex
;
lastReturnedEntry
=
null
;
}
public
V
getValue
()
{
// Provide a better exception than out of bounds index
if
(
lastReturnedIndex
<
0
)
throw
new
IllegalStateException
(
"Entry was removed"
);
private
class
Entry
implements
Map
.
Entry
<
K
,
V
>
{
private
int
index
;
return
(
V
)
traversalTable
[
lastReturnedIndex
+
1
];
}
private
Entry
(
int
index
)
{
this
.
index
=
index
;
}
public
V
setValue
(
V
value
)
{
// It would be mean-spirited to proceed here if remove() called
if
(
lastReturnedIndex
<
0
)
throw
new
IllegalStateException
(
"Entry was removed"
);
V
oldValue
=
(
V
)
traversalTable
[
lastReturnedIndex
+
1
];
traversalTable
[
lastReturnedIndex
+
1
]
=
value
;
// if shadowing, force into main table
if
(
traversalTable
!=
IdentityHashMap
.
this
.
table
)
put
((
K
)
traversalTable
[
lastReturnedIndex
],
value
);
return
oldValue
;
}
public
K
getKey
()
{
checkIndexForEntryUse
();
return
(
K
)
unmaskNull
(
traversalTable
[
index
]);
}
public
boolean
equals
(
Object
o
)
{
if
(
lastReturnedIndex
<
0
)
return
super
.
equals
(
o
);
public
V
getValue
()
{
checkIndexForEntryUse
();
return
(
V
)
traversalTable
[
index
+
1
];
}
if
(!(
o
instanceof
Map
.
Entry
))
return
false
;
Map
.
Entry
e
=
(
Map
.
Entry
)
o
;
return
e
.
getKey
()
==
getKey
()
&&
e
.
getValue
()
==
getValue
();
}
public
V
setValue
(
V
value
)
{
checkIndexForEntryUse
();
V
oldValue
=
(
V
)
traversalTable
[
index
+
1
];
traversalTable
[
index
+
1
]
=
value
;
// if shadowing, force into main table
if
(
traversalTable
!=
IdentityHashMap
.
this
.
table
)
put
((
K
)
traversalTable
[
index
],
value
);
return
oldValue
;
}
public
int
hashCode
(
)
{
if
(
lastReturnedI
ndex
<
0
)
return
super
.
hashCode
(
);
public
boolean
equals
(
Object
o
)
{
if
(
i
ndex
<
0
)
return
super
.
equals
(
o
);
return
System
.
identityHashCode
(
getKey
())
^
System
.
identityHashCode
(
getValue
());
}
if
(!(
o
instanceof
Map
.
Entry
))
return
false
;
Map
.
Entry
e
=
(
Map
.
Entry
)
o
;
return
(
e
.
getKey
()
==
unmaskNull
(
traversalTable
[
index
])
&&
e
.
getValue
()
==
traversalTable
[
index
+
1
]);
}
public
String
toString
()
{
if
(
lastReturnedIndex
<
0
)
return
super
.
toString
();
public
int
hashCode
()
{
if
(
lastReturnedIndex
<
0
)
return
super
.
hashCode
();
return
getKey
()
+
"="
+
getValue
();
return
(
System
.
identityHashCode
(
unmaskNull
(
traversalTable
[
index
]))
^
System
.
identityHashCode
(
traversalTable
[
index
+
1
]));
}
public
String
toString
()
{
if
(
index
<
0
)
return
super
.
toString
();
return
(
unmaskNull
(
traversalTable
[
index
])
+
"="
+
traversalTable
[
index
+
1
]);
}
private
void
checkIndexForEntryUse
()
{
if
(
index
<
0
)
throw
new
IllegalStateException
(
"Entry was removed"
);
}
}
}
...
...
test/java/util/EnumMap/DistinctEntrySetElements.java
0 → 100644
浏览文件 @
aabc7a22
/*
* Copyright (c) 2011 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.
*/
/*
* Portions Copyright (c) 2011 IBM Corporation
*/
/*
* @test
* @bug 6312706
* @summary Sets from Map.entrySet() return distinct objects for each Entry
* @author Neil Richards <neil.richards@ngmr.net>, <neil_richards@uk.ibm.com>
*/
import
java.util.EnumMap
;
import
java.util.HashSet
;
import
java.util.Map
;
import
java.util.Set
;
public
class
DistinctEntrySetElements
{
static
enum
TestEnum
{
e00
,
e01
,
e02
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
final
EnumMap
<
TestEnum
,
String
>
enumMap
=
new
EnumMap
<>(
TestEnum
.
class
);
for
(
TestEnum
e
:
TestEnum
.
values
())
{
enumMap
.
put
(
e
,
e
.
name
());
}
Set
<
Map
.
Entry
<
TestEnum
,
String
>>
entrySet
=
enumMap
.
entrySet
();
HashSet
<
Map
.
Entry
<
TestEnum
,
String
>>
hashSet
=
new
HashSet
<>(
entrySet
);
if
(
false
==
hashSet
.
equals
(
entrySet
))
{
throw
new
RuntimeException
(
"Test FAILED: Sets are not equal."
);
}
if
(
hashSet
.
hashCode
()
!=
entrySet
.
hashCode
())
{
throw
new
RuntimeException
(
"Test FAILED: Set's hashcodes are not equal."
);
}
}
}
test/java/util/EnumMap/EntrySetIteratorRemoveInvalidatesEntry.java
0 → 100644
浏览文件 @
aabc7a22
/*
* Copyright (c) 2011 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.
*/
/*
* Portions Copyright (c) 2011 IBM Corporation
*/
/*
* @test
* @bug 6312706
* @summary Iterator.remove() from Map.entrySet().iterator() invalidates returned Entry.
* @author Neil Richards <neil.richards@ngmr.net>, <neil_richards@uk.ibm.com>
*/
import
java.util.EnumMap
;
import
java.util.Iterator
;
import
java.util.Map
;
public
class
EntrySetIteratorRemoveInvalidatesEntry
{
static
enum
TestEnum
{
e00
,
e01
,
e02
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
final
EnumMap
<
TestEnum
,
String
>
enumMap
=
new
EnumMap
<>(
TestEnum
.
class
);
for
(
TestEnum
e
:
TestEnum
.
values
())
{
enumMap
.
put
(
e
,
e
.
name
());
}
Iterator
<
Map
.
Entry
<
TestEnum
,
String
>>
entrySetIterator
=
enumMap
.
entrySet
().
iterator
();
Map
.
Entry
<
TestEnum
,
String
>
entry
=
entrySetIterator
.
next
();
entrySetIterator
.
remove
();
try
{
entry
.
getKey
();
throw
new
RuntimeException
(
"Test FAILED: Entry not invalidated by removal."
);
}
catch
(
Exception
e
)
{
}
}
}
test/java/util/EnumMap/SimpleSerialization.java
0 → 100644
浏览文件 @
aabc7a22
/*
* Copyright (c) 2011 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.
*/
/*
* Portions Copyright (c) 2011 IBM Corporation
*/
/*
* @test
* @bug 6312706
* @summary A serialized EnumMap can be successfully de-serialized.
* @author Neil Richards <neil.richards@ngmr.net>, <neil_richards@uk.ibm.com>
*/
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
import
java.io.ObjectInputStream
;
import
java.io.ObjectOutputStream
;
import
java.io.PrintWriter
;
import
java.io.StringWriter
;
import
java.util.EnumMap
;
public
class
SimpleSerialization
{
private
enum
TestEnum
{
e00
,
e01
,
e02
,
e03
,
e04
,
e05
,
e06
,
e07
}
public
static
void
main
(
final
String
[]
args
)
throws
Exception
{
final
EnumMap
<
TestEnum
,
String
>
enumMap
=
new
EnumMap
<>(
TestEnum
.
class
);
enumMap
.
put
(
TestEnum
.
e01
,
TestEnum
.
e01
.
name
());
enumMap
.
put
(
TestEnum
.
e04
,
TestEnum
.
e04
.
name
());
enumMap
.
put
(
TestEnum
.
e05
,
TestEnum
.
e05
.
name
());
final
ByteArrayOutputStream
baos
=
new
ByteArrayOutputStream
();
final
ObjectOutputStream
oos
=
new
ObjectOutputStream
(
baos
);
oos
.
writeObject
(
enumMap
);
oos
.
close
();
final
byte
[]
data
=
baos
.
toByteArray
();
final
ByteArrayInputStream
bais
=
new
ByteArrayInputStream
(
data
);
final
ObjectInputStream
ois
=
new
ObjectInputStream
(
bais
);
final
Object
deserializedObject
=
ois
.
readObject
();
ois
.
close
();
if
(
false
==
enumMap
.
equals
(
deserializedObject
))
{
throw
new
RuntimeException
(
getFailureText
(
enumMap
,
deserializedObject
));
}
}
private
static
String
getFailureText
(
final
Object
orig
,
final
Object
copy
)
{
final
StringWriter
sw
=
new
StringWriter
();
final
PrintWriter
pw
=
new
PrintWriter
(
sw
);
pw
.
println
(
"Test FAILED: Deserialized object is not equal to the original object"
);
pw
.
print
(
"\tOriginal: "
);
printObject
(
pw
,
orig
).
println
();
pw
.
print
(
"\tCopy: "
);
printObject
(
pw
,
copy
).
println
();
pw
.
close
();
return
sw
.
toString
();
}
private
static
PrintWriter
printObject
(
final
PrintWriter
pw
,
final
Object
o
)
{
pw
.
printf
(
"%s@%08x"
,
o
.
getClass
().
getName
(),
System
.
identityHashCode
(
o
));
return
pw
;
}
}
test/java/util/IdentityHashMap/DistinctEntrySetElements.java
0 → 100644
浏览文件 @
aabc7a22
/*
* Copyright (c) 2011 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.
*/
/*
* Portions Copyright (c) 2011 IBM Corporation
*/
/*
* @test
* @bug 6312706
* @summary Sets from Map.entrySet() return distinct objects for each Entry
* @author Neil Richards <neil.richards@ngmr.net>, <neil_richards@uk.ibm.com>
*/
import
java.util.IdentityHashMap
;
import
java.util.HashSet
;
import
java.util.Map
;
import
java.util.Set
;
public
class
DistinctEntrySetElements
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
final
IdentityHashMap
<
String
,
String
>
identityHashMap
=
new
IdentityHashMap
<>();
identityHashMap
.
put
(
"One"
,
"Un"
);
identityHashMap
.
put
(
"Two"
,
"Deux"
);
identityHashMap
.
put
(
"Three"
,
"Trois"
);
Set
<
Map
.
Entry
<
String
,
String
>>
entrySet
=
identityHashMap
.
entrySet
();
HashSet
<
Map
.
Entry
<
String
,
String
>>
hashSet
=
new
HashSet
<>(
entrySet
);
// NB: These comparisons are valid in this case because none of the
// keys put into 'identityHashMap' above are equal to any other.
if
(
false
==
hashSet
.
equals
(
entrySet
))
{
throw
new
RuntimeException
(
"Test FAILED: Sets are not equal."
);
}
if
(
hashSet
.
hashCode
()
!=
entrySet
.
hashCode
())
{
throw
new
RuntimeException
(
"Test FAILED: Set's hashcodes are not equal."
);
}
}
}
test/java/util/IdentityHashMap/EntrySetIteratorRemoveInvalidatesEntry.java
0 → 100644
浏览文件 @
aabc7a22
/*
* Copyright (c) 2011 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.
*/
/*
* Portions Copyright (c) 2011 IBM Corporation
*/
/*
* @test
* @bug 6312706
* @summary Iterator.remove() from Map.entrySet().iterator() invalidates returned Entry.
* @author Neil Richards <neil.richards@ngmr.net>, <neil_richards@uk.ibm.com>
*/
import
java.util.IdentityHashMap
;
import
java.util.Iterator
;
import
java.util.Map
;
public
class
EntrySetIteratorRemoveInvalidatesEntry
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
final
IdentityHashMap
<
String
,
String
>
identityHashMap
=
new
IdentityHashMap
<>();
identityHashMap
.
put
(
"One"
,
"Un"
);
identityHashMap
.
put
(
"Two"
,
"Deux"
);
identityHashMap
.
put
(
"Three"
,
"Trois"
);
Iterator
<
Map
.
Entry
<
String
,
String
>>
entrySetIterator
=
identityHashMap
.
entrySet
().
iterator
();
Map
.
Entry
<
String
,
String
>
entry
=
entrySetIterator
.
next
();
entrySetIterator
.
remove
();
try
{
entry
.
getKey
();
throw
new
RuntimeException
(
"Test FAILED: Entry not invalidated by removal."
);
}
catch
(
Exception
e
)
{
}
}
}
test/java/util/ResourceBundle/Bug4168625Test.java
浏览文件 @
aabc7a22
...
...
@@ -282,7 +282,7 @@ public class Bug4168625Test extends RBTestFmwk {
thread1
.
start
();
//start thread 1
loader
.
waitForNotify
(
1
);
//wait for thread1 to do getBundle & block in loader
thread2
.
start
();
//start second thread
thread2
.
join
(
1000
);
//wait until thread2 blocks somewhere in getBundle
thread2
.
join
(
);
//wait until thread2 terminates.
//Thread1 should be blocked inside getBundle at the class loader
//Thread2 should have completed its getBundle call and terminated
...
...
@@ -292,7 +292,6 @@ public class Bug4168625Test extends RBTestFmwk {
thread1
.
ping
();
//continue thread1
thread1
.
join
();
thread2
.
join
();
}
/**
...
...
@@ -318,8 +317,7 @@ public class Bug4168625Test extends RBTestFmwk {
loader
.
waitForNotify
(
3
);
//wait for thread1 to do getBundle(en) & block in loader
causeResourceBundleCacheFlush
();
//cause a cache flush
thread1
.
ping
();
//kick thread 1
thread1
.
ping
();
//kick thread 1
thread1
.
join
(
1000
);
//wait until thread2 blocks somewhere in getBundle
thread1
.
join
();
//wait until thread1 terminates
ResourceBundle
bundle
=
(
ResourceBundle
)
thread1
.
bundle
;
String
s1
=
bundle
.
getString
(
"Bug4168625Resource3_en_US"
);
...
...
test/java/util/concurrent/ConcurrentHashMap/DistinctEntrySetElements.java
0 → 100644
浏览文件 @
aabc7a22
/*
* Copyright (c) 2011 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.
*/
/*
* Portions Copyright (c) 2011 IBM Corporation
*/
/*
* @test
* @bug 6312706
* @summary Sets from Map.entrySet() return distinct objects for each Entry
* @author Neil Richards <neil.richards@ngmr.net>, <neil_richards@uk.ibm.com>
*/
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.HashSet
;
import
java.util.Map
;
import
java.util.Set
;
public
class
DistinctEntrySetElements
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
final
ConcurrentHashMap
<
String
,
String
>
concurrentHashMap
=
new
ConcurrentHashMap
<>();
concurrentHashMap
.
put
(
"One"
,
"Un"
);
concurrentHashMap
.
put
(
"Two"
,
"Deux"
);
concurrentHashMap
.
put
(
"Three"
,
"Trois"
);
Set
<
Map
.
Entry
<
String
,
String
>>
entrySet
=
concurrentHashMap
.
entrySet
();
HashSet
<
Map
.
Entry
<
String
,
String
>>
hashSet
=
new
HashSet
<>(
entrySet
);
if
(
false
==
hashSet
.
equals
(
entrySet
))
{
throw
new
RuntimeException
(
"Test FAILED: Sets are not equal."
);
}
if
(
hashSet
.
hashCode
()
!=
entrySet
.
hashCode
())
{
throw
new
RuntimeException
(
"Test FAILED: Set's hashcodes are not equal."
);
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录