test/tools/javac/T5053846/MethodRefDupInConstantPoolTest.java

Fri, 15 Mar 2013 09:02:26 +0000

author
vromero
date
Fri, 15 Mar 2013 09:02:26 +0000
changeset 1640
fa24eba012bd
child 1687
a4be2c2fe0a1
permissions
-rw-r--r--

5053846: javac: MethodRef entries are duplicated in the constant pool
Reviewed-by: mcimadamore

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

mercurial