Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/util/LinkedList/Clone.java
38812 views
/*1* Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 421699726* @summary Cloning a subclass of LinkedList results in an object that isn't27* an instance of the subclass. The same applies to TreeSet and28* TreeMap.29*/3031import java.util.*;3233public class Clone {34public static void main(String[] args) {35LinkedList2 l = new LinkedList2();36LinkedList2 lClone = (LinkedList2) l.clone();37if (!(l.equals(lClone) && lClone.equals(l)))38throw new RuntimeException("LinkedList.clone() is broken 1.");39l.add("a");40lClone = (LinkedList2) l.clone();41if (!(l.equals(lClone) && lClone.equals(l)))42throw new RuntimeException("LinkedList.clone() is broken 2.");43l.add("b");44lClone = (LinkedList2) l.clone();45if (!(l.equals(lClone) && lClone.equals(l)))46throw new RuntimeException("LinkedList.clone() is broken 2.");474849TreeSet2 s = new TreeSet2();50TreeSet2 sClone = (TreeSet2) s.clone();51if (!(s.equals(sClone) && sClone.equals(s)))52throw new RuntimeException("TreeSet.clone() is broken.");53s.add("a");54sClone = (TreeSet2) s.clone();55if (!(s.equals(sClone) && sClone.equals(s)))56throw new RuntimeException("TreeSet.clone() is broken.");57s.add("b");58sClone = (TreeSet2) s.clone();59if (!(s.equals(sClone) && sClone.equals(s)))60throw new RuntimeException("TreeSet.clone() is broken.");6162TreeMap2 m = new TreeMap2();63TreeMap2 mClone = (TreeMap2) m.clone();64if (!(m.equals(mClone) && mClone.equals(m)))65throw new RuntimeException("TreeMap.clone() is broken.");66m.put("a", "b");67mClone = (TreeMap2) m.clone();68if (!(m.equals(mClone) && mClone.equals(m)))69throw new RuntimeException("TreeMap.clone() is broken.");70m.put("c", "d");71mClone = (TreeMap2) m.clone();72if (!(m.equals(mClone) && mClone.equals(m)))73throw new RuntimeException("TreeMap.clone() is broken.");74}7576private static class LinkedList2 extends LinkedList {};77private static class TreeSet2 extends TreeSet {};78private static class TreeMap2 extends TreeMap {};79}808182