jdk/test/java/util/TreeMap/Clone.java
author ctornqvi
Thu, 16 May 2013 15:31:00 +0200
changeset 17598 f78d22d3c6c2
parent 14661 d8df617b9e98
child 20475 a649487986eb
permissions -rw-r--r--
8008169: test/runtime/7158804/Test7158804.sh has bad copyright header Summary: Re-wrote test in Java in addition to fixing the Copyright notice. Also reviewed by leonid.mesnik@oracle.com Reviewed-by: coleenp, ctornqvi Contributed-by: Mikhailo Seledtsov <mikhailo.seledtsov@oracle.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14661
d8df617b9e98 7198904: (alt-rt) TreeMap.clone is broken
dbuck
parents:
diff changeset
     1
/*
d8df617b9e98 7198904: (alt-rt) TreeMap.clone is broken
dbuck
parents:
diff changeset
     2
 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
d8df617b9e98 7198904: (alt-rt) TreeMap.clone is broken
dbuck
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d8df617b9e98 7198904: (alt-rt) TreeMap.clone is broken
dbuck
parents:
diff changeset
     4
 *
d8df617b9e98 7198904: (alt-rt) TreeMap.clone is broken
dbuck
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
d8df617b9e98 7198904: (alt-rt) TreeMap.clone is broken
dbuck
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
d8df617b9e98 7198904: (alt-rt) TreeMap.clone is broken
dbuck
parents:
diff changeset
     7
 * published by the Free Software Foundation.
d8df617b9e98 7198904: (alt-rt) TreeMap.clone is broken
dbuck
parents:
diff changeset
     8
 *
d8df617b9e98 7198904: (alt-rt) TreeMap.clone is broken
dbuck
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
d8df617b9e98 7198904: (alt-rt) TreeMap.clone is broken
dbuck
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d8df617b9e98 7198904: (alt-rt) TreeMap.clone is broken
dbuck
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d8df617b9e98 7198904: (alt-rt) TreeMap.clone is broken
dbuck
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
d8df617b9e98 7198904: (alt-rt) TreeMap.clone is broken
dbuck
parents:
diff changeset
    13
 * accompanied this code).
d8df617b9e98 7198904: (alt-rt) TreeMap.clone is broken
dbuck
parents:
diff changeset
    14
 *
d8df617b9e98 7198904: (alt-rt) TreeMap.clone is broken
dbuck
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
d8df617b9e98 7198904: (alt-rt) TreeMap.clone is broken
dbuck
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
d8df617b9e98 7198904: (alt-rt) TreeMap.clone is broken
dbuck
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d8df617b9e98 7198904: (alt-rt) TreeMap.clone is broken
dbuck
parents:
diff changeset
    18
 *
d8df617b9e98 7198904: (alt-rt) TreeMap.clone is broken
dbuck
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d8df617b9e98 7198904: (alt-rt) TreeMap.clone is broken
dbuck
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
d8df617b9e98 7198904: (alt-rt) TreeMap.clone is broken
dbuck
parents:
diff changeset
    21
 * questions.
d8df617b9e98 7198904: (alt-rt) TreeMap.clone is broken
dbuck
parents:
diff changeset
    22
 */
d8df617b9e98 7198904: (alt-rt) TreeMap.clone is broken
dbuck
parents:
diff changeset
    23
d8df617b9e98 7198904: (alt-rt) TreeMap.clone is broken
dbuck
parents:
diff changeset
    24
/**
d8df617b9e98 7198904: (alt-rt) TreeMap.clone is broken
dbuck
parents:
diff changeset
    25
 * @test
d8df617b9e98 7198904: (alt-rt) TreeMap.clone is broken
dbuck
parents:
diff changeset
    26
 * @bug 7198904
d8df617b9e98 7198904: (alt-rt) TreeMap.clone is broken
dbuck
parents:
diff changeset
    27
 * @summary Verify that cloned TreeMap gets new keyset
d8df617b9e98 7198904: (alt-rt) TreeMap.clone is broken
dbuck
parents:
diff changeset
    28
 * @author david.buck@oracle.com
d8df617b9e98 7198904: (alt-rt) TreeMap.clone is broken
dbuck
parents:
diff changeset
    29
 * @run main/othervm Clone
d8df617b9e98 7198904: (alt-rt) TreeMap.clone is broken
dbuck
parents:
diff changeset
    30
 * @run main/othervm -XX:+AggressiveOpts Clone
d8df617b9e98 7198904: (alt-rt) TreeMap.clone is broken
dbuck
parents:
diff changeset
    31
 */
d8df617b9e98 7198904: (alt-rt) TreeMap.clone is broken
dbuck
parents:
diff changeset
    32
d8df617b9e98 7198904: (alt-rt) TreeMap.clone is broken
dbuck
parents:
diff changeset
    33
import java.util.TreeMap;
d8df617b9e98 7198904: (alt-rt) TreeMap.clone is broken
dbuck
parents:
diff changeset
    34
d8df617b9e98 7198904: (alt-rt) TreeMap.clone is broken
dbuck
parents:
diff changeset
    35
public class Clone  {
d8df617b9e98 7198904: (alt-rt) TreeMap.clone is broken
dbuck
parents:
diff changeset
    36
d8df617b9e98 7198904: (alt-rt) TreeMap.clone is broken
dbuck
parents:
diff changeset
    37
    public static void main(String[] args) throws Exception {
d8df617b9e98 7198904: (alt-rt) TreeMap.clone is broken
dbuck
parents:
diff changeset
    38
        TreeMap<String,Object> m1 = new TreeMap<String,Object>();
d8df617b9e98 7198904: (alt-rt) TreeMap.clone is broken
dbuck
parents:
diff changeset
    39
        m1.put( "one", 1 );
d8df617b9e98 7198904: (alt-rt) TreeMap.clone is broken
dbuck
parents:
diff changeset
    40
        m1.keySet();
d8df617b9e98 7198904: (alt-rt) TreeMap.clone is broken
dbuck
parents:
diff changeset
    41
        TreeMap<String,Object> m2 = (TreeMap<String,Object>)m1.clone();
d8df617b9e98 7198904: (alt-rt) TreeMap.clone is broken
dbuck
parents:
diff changeset
    42
        m1.put( "two", 2 );
d8df617b9e98 7198904: (alt-rt) TreeMap.clone is broken
dbuck
parents:
diff changeset
    43
        m2.put( "three", 3 );
d8df617b9e98 7198904: (alt-rt) TreeMap.clone is broken
dbuck
parents:
diff changeset
    44
        // iterate over the clone (m2) and we should get "one" and "three"
d8df617b9e98 7198904: (alt-rt) TreeMap.clone is broken
dbuck
parents:
diff changeset
    45
        for( final String key : m2.keySet() ) {
d8df617b9e98 7198904: (alt-rt) TreeMap.clone is broken
dbuck
parents:
diff changeset
    46
            if( !"one".equals( key ) && !"three".equals( key ) ) {
d8df617b9e98 7198904: (alt-rt) TreeMap.clone is broken
dbuck
parents:
diff changeset
    47
                throw new IllegalStateException( "Unexpected key: " + key );
d8df617b9e98 7198904: (alt-rt) TreeMap.clone is broken
dbuck
parents:
diff changeset
    48
            }
d8df617b9e98 7198904: (alt-rt) TreeMap.clone is broken
dbuck
parents:
diff changeset
    49
        }
d8df617b9e98 7198904: (alt-rt) TreeMap.clone is broken
dbuck
parents:
diff changeset
    50
        // iterate over the original (m1) and we should get "one" and "two"
d8df617b9e98 7198904: (alt-rt) TreeMap.clone is broken
dbuck
parents:
diff changeset
    51
        for( final String key : m1.keySet() ) {
d8df617b9e98 7198904: (alt-rt) TreeMap.clone is broken
dbuck
parents:
diff changeset
    52
            if( !"one".equals( key ) && !"two".equals( key ) ) {
d8df617b9e98 7198904: (alt-rt) TreeMap.clone is broken
dbuck
parents:
diff changeset
    53
                throw new IllegalStateException( "Unexpected key: " + key );
d8df617b9e98 7198904: (alt-rt) TreeMap.clone is broken
dbuck
parents:
diff changeset
    54
            }
d8df617b9e98 7198904: (alt-rt) TreeMap.clone is broken
dbuck
parents:
diff changeset
    55
        }
d8df617b9e98 7198904: (alt-rt) TreeMap.clone is broken
dbuck
parents:
diff changeset
    56
    }
d8df617b9e98 7198904: (alt-rt) TreeMap.clone is broken
dbuck
parents:
diff changeset
    57
d8df617b9e98 7198904: (alt-rt) TreeMap.clone is broken
dbuck
parents:
diff changeset
    58
}