author | dl |
Fri, 03 Feb 2017 13:24:59 -0800 | |
changeset 43522 | f9c6f543c4db |
parent 9734 | b33a24d77590 |
permissions | -rw-r--r-- |
9235
ddd556c97e6c
6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff
changeset
|
1 |
/* |
9734
b33a24d77590
7044486: open jdk repos have files with incorrect copyright headers, which can end up in src bundles
katleman
parents:
9235
diff
changeset
|
2 |
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. |
9235
ddd556c97e6c
6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ddd556c97e6c
6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff
changeset
|
4 |
* |
ddd556c97e6c
6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
ddd556c97e6c
6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
ddd556c97e6c
6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
ddd556c97e6c
6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff
changeset
|
8 |
* |
ddd556c97e6c
6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
ddd556c97e6c
6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ddd556c97e6c
6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ddd556c97e6c
6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
ddd556c97e6c
6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff
changeset
|
13 |
* accompanied this code). |
ddd556c97e6c
6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff
changeset
|
14 |
* |
ddd556c97e6c
6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
ddd556c97e6c
6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
ddd556c97e6c
6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ddd556c97e6c
6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff
changeset
|
18 |
* |
ddd556c97e6c
6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ddd556c97e6c
6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
ddd556c97e6c
6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff
changeset
|
21 |
* questions. |
ddd556c97e6c
6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff
changeset
|
22 |
*/ |
ddd556c97e6c
6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff
changeset
|
23 |
|
ddd556c97e6c
6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff
changeset
|
24 |
/* |
ddd556c97e6c
6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff
changeset
|
25 |
* Portions Copyright (c) 2011 IBM Corporation |
ddd556c97e6c
6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff
changeset
|
26 |
*/ |
ddd556c97e6c
6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff
changeset
|
27 |
|
ddd556c97e6c
6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff
changeset
|
28 |
/* |
ddd556c97e6c
6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff
changeset
|
29 |
* @test |
ddd556c97e6c
6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff
changeset
|
30 |
* @bug 6312706 |
ddd556c97e6c
6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff
changeset
|
31 |
* @summary Iterator.remove() from Map.entrySet().iterator() invalidates returned Entry. |
ddd556c97e6c
6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff
changeset
|
32 |
* @author Neil Richards <neil.richards@ngmr.net>, <neil_richards@uk.ibm.com> |
ddd556c97e6c
6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff
changeset
|
33 |
*/ |
ddd556c97e6c
6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff
changeset
|
34 |
|
ddd556c97e6c
6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff
changeset
|
35 |
import java.util.IdentityHashMap; |
ddd556c97e6c
6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff
changeset
|
36 |
import java.util.Iterator; |
ddd556c97e6c
6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff
changeset
|
37 |
import java.util.Map; |
ddd556c97e6c
6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff
changeset
|
38 |
|
ddd556c97e6c
6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff
changeset
|
39 |
public class EntrySetIteratorRemoveInvalidatesEntry { |
ddd556c97e6c
6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff
changeset
|
40 |
public static void main(String[] args) throws Exception { |
ddd556c97e6c
6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff
changeset
|
41 |
final IdentityHashMap<String, String> identityHashMap = |
ddd556c97e6c
6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff
changeset
|
42 |
new IdentityHashMap<>(); |
ddd556c97e6c
6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff
changeset
|
43 |
|
ddd556c97e6c
6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff
changeset
|
44 |
identityHashMap.put("One", "Un"); |
ddd556c97e6c
6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff
changeset
|
45 |
identityHashMap.put("Two", "Deux"); |
ddd556c97e6c
6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff
changeset
|
46 |
identityHashMap.put("Three", "Trois"); |
ddd556c97e6c
6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff
changeset
|
47 |
|
ddd556c97e6c
6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff
changeset
|
48 |
Iterator<Map.Entry<String, String>> entrySetIterator = |
ddd556c97e6c
6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff
changeset
|
49 |
identityHashMap.entrySet().iterator(); |
ddd556c97e6c
6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff
changeset
|
50 |
Map.Entry<String, String> entry = entrySetIterator.next(); |
ddd556c97e6c
6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff
changeset
|
51 |
|
ddd556c97e6c
6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff
changeset
|
52 |
entrySetIterator.remove(); |
ddd556c97e6c
6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff
changeset
|
53 |
|
ddd556c97e6c
6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff
changeset
|
54 |
try { |
ddd556c97e6c
6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff
changeset
|
55 |
entry.getKey(); |
ddd556c97e6c
6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff
changeset
|
56 |
throw new RuntimeException("Test FAILED: Entry not invalidated by removal."); |
ddd556c97e6c
6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff
changeset
|
57 |
} catch (Exception e) { } |
ddd556c97e6c
6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff
changeset
|
58 |
} |
ddd556c97e6c
6312706: Map entrySet iterators should return different entries on each call to next()
mduigou
parents:
diff
changeset
|
59 |
} |