Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/util/AbstractMap/AbstractMapClone.java
38813 views
/*1* Copyright (c) 2000, 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 432874826* @summary AbstractMap's clone() method is implemented to27* reset AbstractMap's private fields after super.clone()28*29* @author Konstantin Kladko30*/3132import java.util.*;3334public class AbstractMapClone extends AbstractMap implements Cloneable {3536private Map map = new HashMap();3738public Set entrySet() {39return map.entrySet();40}4142public Object put(Object key, Object value) {43return map.put(key, value);44}4546public Object clone() {47AbstractMapClone clone = null;48try {49clone = (AbstractMapClone)super.clone();50} catch (CloneNotSupportedException e) {51}52clone.map = (Map)((HashMap)map).clone();53return clone;54}5556public static void main(String[] args) {57AbstractMapClone m1 = new AbstractMapClone();58m1.put("1", "1");59Set k1 = m1.keySet();60AbstractMapClone m2 = (AbstractMapClone)m1.clone();61Set k2 = m2.keySet();62m2.put("2","2");63if (k1.equals(k2)) {64throw new RuntimeException("AbstractMap.clone() failed.");65}66}67}686970