langtools/test/tools/javac/T5053846/MethodRefDupInConstantPoolTest.java
author sogoel
Thu, 05 Jun 2014 10:57:10 -0700
changeset 24797 850ebd4d80a7
parent 16965 e00f419042b7
child 30730 d3ce7619db2c
permissions -rw-r--r--
8044072: Group 2: create .out files for OverrideChecks tests in tools/javac dir Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16552
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
     1
/*
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
     2
 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
     4
 *
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
     7
 * published by the Free Software Foundation.
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
     8
 *
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
    13
 * accompanied this code).
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
    14
 *
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
    18
 *
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
    21
 * questions.
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
    22
 */
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
    23
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
    24
/*
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
    25
 * @test
16965
e00f419042b7 8011432: javac, compiler regression iterable + captured type
vromero
parents: 16552
diff changeset
    26
 * @bug 5053846 8011432
16552
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
    27
 * @summary javac: MethodRef entries are duplicated in the constant pool
16965
e00f419042b7 8011432: javac, compiler regression iterable + captured type
vromero
parents: 16552
diff changeset
    28
 * @summary javac, compiler regression iterable + captured type
16552
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
    29
 */
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
    30
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
    31
import java.io.PrintWriter;
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
    32
import java.io.StringWriter;
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
    33
import java.nio.file.Paths;
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
    34
import java.util.*;
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
    35
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
    36
public class MethodRefDupInConstantPoolTest {
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
    37
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
    38
    private static final String methodToLookFor =
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
    39
            "java/util/Vector.iterator:()Ljava/util/Iterator;";
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
    40
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
    41
    public static void main(String[] args) {
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
    42
        new MethodRefDupInConstantPoolTest().run();
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
    43
    }
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
    44
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
    45
    void run() {
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
    46
        check("-v", Paths.get(System.getProperty("test.classes"),
16965
e00f419042b7 8011432: javac, compiler regression iterable + captured type
vromero
parents: 16552
diff changeset
    47
                this.getClass().getSimpleName() + "$TestHelper1.class").toString());
e00f419042b7 8011432: javac, compiler regression iterable + captured type
vromero
parents: 16552
diff changeset
    48
        check("-v", Paths.get(System.getProperty("test.classes"),
e00f419042b7 8011432: javac, compiler regression iterable + captured type
vromero
parents: 16552
diff changeset
    49
                this.getClass().getSimpleName() + "$TestHelper2.class").toString());
16552
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
    50
        check("-v", Paths.get(System.getProperty("test.classes"),
16965
e00f419042b7 8011432: javac, compiler regression iterable + captured type
vromero
parents: 16552
diff changeset
    51
                this.getClass().getSimpleName() + "$TestHelper3.class").toString());
e00f419042b7 8011432: javac, compiler regression iterable + captured type
vromero
parents: 16552
diff changeset
    52
        check("-v", Paths.get(System.getProperty("test.classes"),
e00f419042b7 8011432: javac, compiler regression iterable + captured type
vromero
parents: 16552
diff changeset
    53
                this.getClass().getSimpleName() + "$TestHelper4.class").toString());
16552
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
    54
    }
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
    55
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
    56
    void check(String... params) {
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
    57
        StringWriter s;
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
    58
        String out;
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
    59
        try (PrintWriter pw = new PrintWriter(s = new StringWriter())) {
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
    60
            com.sun.tools.javap.Main.run(params, pw);
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
    61
            out = s.toString();
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
    62
        }
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
    63
        String constantPool = getConstantPool(out);
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
    64
        if (constantPool.indexOf(methodToLookFor) !=
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
    65
                constantPool.lastIndexOf(methodToLookFor)) {
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
    66
            throw new AssertionError("There is more than one entry for the method seek "  +
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
    67
                    methodToLookFor);
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
    68
        }
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
    69
    }
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
    70
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
    71
    String getConstantPool(String out) {
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
    72
        int start = out.indexOf("Constant pool:");
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
    73
        int end = out.indexOf("{");
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
    74
        return out.substring(start, end);
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
    75
    }
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
    76
16965
e00f419042b7 8011432: javac, compiler regression iterable + captured type
vromero
parents: 16552
diff changeset
    77
    class TestHelper1 {
e00f419042b7 8011432: javac, compiler regression iterable + captured type
vromero
parents: 16552
diff changeset
    78
        void m() {
e00f419042b7 8011432: javac, compiler regression iterable + captured type
vromero
parents: 16552
diff changeset
    79
            Vector v = new Vector();
e00f419042b7 8011432: javac, compiler regression iterable + captured type
vromero
parents: 16552
diff changeset
    80
            Iterator iter = v.iterator();
e00f419042b7 8011432: javac, compiler regression iterable + captured type
vromero
parents: 16552
diff changeset
    81
            while (iter.hasNext()) {
e00f419042b7 8011432: javac, compiler regression iterable + captured type
vromero
parents: 16552
diff changeset
    82
                Object o = iter.next();
e00f419042b7 8011432: javac, compiler regression iterable + captured type
vromero
parents: 16552
diff changeset
    83
                Object o2 = o;
e00f419042b7 8011432: javac, compiler regression iterable + captured type
vromero
parents: 16552
diff changeset
    84
            }
e00f419042b7 8011432: javac, compiler regression iterable + captured type
vromero
parents: 16552
diff changeset
    85
            for (Object o: v) {
e00f419042b7 8011432: javac, compiler regression iterable + captured type
vromero
parents: 16552
diff changeset
    86
                Object o2 = o;
e00f419042b7 8011432: javac, compiler regression iterable + captured type
vromero
parents: 16552
diff changeset
    87
            }
16552
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
    88
        }
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
    89
    }
16965
e00f419042b7 8011432: javac, compiler regression iterable + captured type
vromero
parents: 16552
diff changeset
    90
e00f419042b7 8011432: javac, compiler regression iterable + captured type
vromero
parents: 16552
diff changeset
    91
    class TestHelper2<X extends Number & Iterable<String>> {
e00f419042b7 8011432: javac, compiler regression iterable + captured type
vromero
parents: 16552
diff changeset
    92
        void test(X x) {
e00f419042b7 8011432: javac, compiler regression iterable + captured type
vromero
parents: 16552
diff changeset
    93
            for (String s : x) { }
e00f419042b7 8011432: javac, compiler regression iterable + captured type
vromero
parents: 16552
diff changeset
    94
        }
e00f419042b7 8011432: javac, compiler regression iterable + captured type
vromero
parents: 16552
diff changeset
    95
    }
e00f419042b7 8011432: javac, compiler regression iterable + captured type
vromero
parents: 16552
diff changeset
    96
e00f419042b7 8011432: javac, compiler regression iterable + captured type
vromero
parents: 16552
diff changeset
    97
    interface Data extends Iterable<String> {}
16552
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
    98
16965
e00f419042b7 8011432: javac, compiler regression iterable + captured type
vromero
parents: 16552
diff changeset
    99
    class TestHelper3<X extends Number & Iterable<? extends Data>> {
e00f419042b7 8011432: javac, compiler regression iterable + captured type
vromero
parents: 16552
diff changeset
   100
        void test(X x) {
e00f419042b7 8011432: javac, compiler regression iterable + captured type
vromero
parents: 16552
diff changeset
   101
            for (Data s : x) { }
e00f419042b7 8011432: javac, compiler regression iterable + captured type
vromero
parents: 16552
diff changeset
   102
        }
e00f419042b7 8011432: javac, compiler regression iterable + captured type
vromero
parents: 16552
diff changeset
   103
    }
e00f419042b7 8011432: javac, compiler regression iterable + captured type
vromero
parents: 16552
diff changeset
   104
e00f419042b7 8011432: javac, compiler regression iterable + captured type
vromero
parents: 16552
diff changeset
   105
    class TestHelper4 {
e00f419042b7 8011432: javac, compiler regression iterable + captured type
vromero
parents: 16552
diff changeset
   106
         void test(Iterable<? extends Data> t) {
e00f419042b7 8011432: javac, compiler regression iterable + captured type
vromero
parents: 16552
diff changeset
   107
             for(Object a: t.iterator().next());
e00f419042b7 8011432: javac, compiler regression iterable + captured type
vromero
parents: 16552
diff changeset
   108
         }
16552
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
   109
    }
59519c4e7603 5053846: javac: MethodRef entries are duplicated in the constant pool
vromero
parents:
diff changeset
   110
}