ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/jtreg/util/LinkedList/Clone.java
Revision: 1.3
Committed: Wed Dec 31 05:04:04 2014 UTC (9 years, 4 months ago) by jsr166
Branch: MAIN
Changes since 1.2: +3 -3 lines
Log Message:
delete stray semicolons

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 4216997
27 * @summary Cloning a subclass of LinkedList results in an object that isn't
28 * an instance of the subclass. The same applies to TreeSet and
29 * TreeMap.
30 */
31
32 import java.util.*;
33
34 public class Clone {
35 public static void main(String[] args) {
36 LinkedList2 l = new LinkedList2();
37 LinkedList2 lClone = (LinkedList2) l.clone();
38 if (!(l.equals(lClone) && lClone.equals(l)))
39 throw new RuntimeException("LinkedList.clone() is broken 1.");
40 l.add("a");
41 lClone = (LinkedList2) l.clone();
42 if (!(l.equals(lClone) && lClone.equals(l)))
43 throw new RuntimeException("LinkedList.clone() is broken 2.");
44 l.add("b");
45 lClone = (LinkedList2) l.clone();
46 if (!(l.equals(lClone) && lClone.equals(l)))
47 throw new RuntimeException("LinkedList.clone() is broken 2.");
48
49
50 TreeSet2 s = new TreeSet2();
51 TreeSet2 sClone = (TreeSet2) s.clone();
52 if (!(s.equals(sClone) && sClone.equals(s)))
53 throw new RuntimeException("TreeSet.clone() is broken.");
54 s.add("a");
55 sClone = (TreeSet2) s.clone();
56 if (!(s.equals(sClone) && sClone.equals(s)))
57 throw new RuntimeException("TreeSet.clone() is broken.");
58 s.add("b");
59 sClone = (TreeSet2) s.clone();
60 if (!(s.equals(sClone) && sClone.equals(s)))
61 throw new RuntimeException("TreeSet.clone() is broken.");
62
63 TreeMap2 m = new TreeMap2();
64 TreeMap2 mClone = (TreeMap2) m.clone();
65 if (!(m.equals(mClone) && mClone.equals(m)))
66 throw new RuntimeException("TreeMap.clone() is broken.");
67 m.put("a", "b");
68 mClone = (TreeMap2) m.clone();
69 if (!(m.equals(mClone) && mClone.equals(m)))
70 throw new RuntimeException("TreeMap.clone() is broken.");
71 m.put("c", "d");
72 mClone = (TreeMap2) m.clone();
73 if (!(m.equals(mClone) && mClone.equals(m)))
74 throw new RuntimeException("TreeMap.clone() is broken.");
75 }
76
77 private static class LinkedList2 extends LinkedList {}
78 private static class TreeSet2 extends TreeSet {}
79 private static class TreeMap2 extends TreeMap {}
80 }