ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/jtreg/util/AbstractList/FailFastIterator.java
Revision: 1.6
Committed: Mon Jan 8 03:12:03 2018 UTC (6 years, 4 months ago) by jsr166
Branch: MAIN
CVS Tags: HEAD
Changes since 1.5: +4 -1 lines
Log Message:
organize imports

File Contents

# Content
1 /*
2 * Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * @test
26 * @bug 4189896
27 * @summary AbstractList iterators previously checked for co-modification
28 * *after* the set/add/remove operations were performed.
29 */
30
31 import java.util.ArrayList;
32 import java.util.ConcurrentModificationException;
33 import java.util.List;
34 import java.util.ListIterator;
35
36 public class FailFastIterator {
37 public static void main(String[] args) throws Exception {
38 List orig = new ArrayList(100);
39 for (int i=0; i<100; i++)
40 orig.add(new Integer(i));
41
42 List copy = new ArrayList(orig);
43 try {
44 ListIterator i = copy.listIterator();
45 i.next();
46 copy.remove(99);
47 copy.add(new Integer(99));
48 i.remove();
49 throw new Exception("remove: iterator didn't fail fast");
50 } catch (ConcurrentModificationException e) {
51 }
52 if (!copy.equals(orig))
53 throw new Exception("remove: iterator didn't fail fast enough");
54
55 try {
56 ListIterator i = copy.listIterator();
57 i.next();
58 copy.remove(99);
59 copy.add(new Integer(99));
60 i.set(new Integer(666));
61 throw new Exception("set: iterator didn't fail fast");
62 } catch (ConcurrentModificationException e) {
63 }
64 if (!copy.equals(orig))
65 throw new Exception("set: iterator didn't fail fast enough");
66
67 try {
68 ListIterator i = copy.listIterator();
69 copy.remove(99);
70 copy.add(new Integer(99));
71 i.add(new Integer(666));
72 throw new Exception("add: iterator didn't fail fast");
73 } catch (ConcurrentModificationException e) {
74 }
75 if (!copy.equals(orig))
76 throw new Exception("add: iterator didn't fail fast enough");
77 }
78 }