5499N/A/*
5499N/A * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
5499N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5499N/A *
5499N/A * This code is free software; you can redistribute it and/or modify it
5499N/A * under the terms of the GNU General Public License version 2 only, as
5499N/A * published by the Free Software Foundation.
5499N/A *
5499N/A * This code is distributed in the hope that it will be useful, but WITHOUT
5499N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5499N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5499N/A * version 2 for more details (a copy is included in the LICENSE file that
5499N/A * accompanied this code).
5499N/A *
5499N/A * You should have received a copy of the GNU General Public License version
5499N/A * 2 along with this work; if not, write to the Free Software Foundation,
5499N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5499N/A *
5499N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5499N/A * or visit www.oracle.com if you need additional information or have any
5499N/A * questions.
5499N/A */
5499N/A
5499N/A/**
5499N/A * @test
5499N/A * @bug 7198904
5499N/A * @summary Verify that cloned TreeMap gets new keyset
5499N/A * @author david.buck@oracle.com
5499N/A * @run main/othervm Clone
5499N/A * @run main/othervm -XX:+AggressiveOpts Clone
5499N/A */
5499N/A
5499N/Aimport java.util.TreeMap;
5499N/A
5499N/Apublic class Clone {
5499N/A
5499N/A public static void main(String[] args) throws Exception {
5499N/A TreeMap<String,Object> m1 = new TreeMap<String,Object>();
5499N/A m1.put( "one", 1 );
5499N/A m1.keySet();
5499N/A TreeMap<String,Object> m2 = (TreeMap<String,Object>)m1.clone();
5499N/A m1.put( "two", 2 );
5499N/A m2.put( "three", 3 );
5499N/A // iterate over the clone (m2) and we should get "one" and "three"
5499N/A for( final String key : m2.keySet() ) {
5499N/A if( !"one".equals( key ) && !"three".equals( key ) ) {
5499N/A throw new IllegalStateException( "Unexpected key: " + key );
5499N/A }
5499N/A }
5499N/A // iterate over the original (m1) and we should get "one" and "two"
5499N/A for( final String key : m1.keySet() ) {
5499N/A if( !"one".equals( key ) && !"two".equals( key ) ) {
5499N/A throw new IllegalStateException( "Unexpected key: " + key );
5499N/A }
5499N/A }
5499N/A }
5499N/A
5499N/A}