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

# User Rev Content
1 jsr166 1.1 /*
2 jsr166 1.3 * Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved.
3 jsr166 1.1 * 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 jsr166 1.3 * 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 jsr166 1.1 */
23    
24 jsr166 1.5 /*
25 jsr166 1.1 * @test
26     * @bug 4189896
27 jsr166 1.4 * @summary AbstractList iterators previously checked for co-modification
28 jsr166 1.1 * *after* the set/add/remove operations were performed.
29     */
30    
31 jsr166 1.6 import java.util.ArrayList;
32     import java.util.ConcurrentModificationException;
33     import java.util.List;
34     import java.util.ListIterator;
35 jsr166 1.1
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 jsr166 1.2 } catch (ConcurrentModificationException e) {
51 jsr166 1.1 }
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 jsr166 1.2 } catch (ConcurrentModificationException e) {
63 jsr166 1.1 }
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 jsr166 1.2 } catch (ConcurrentModificationException e) {
74 jsr166 1.1 }
75     if (!copy.equals(orig))
76     throw new Exception("add: iterator didn't fail fast enough");
77     }
78     }