Fri, 15 Mar 2013 09:02:26 +0000
5053846: javac: MethodRef entries are duplicated in the constant pool
Reviewed-by: mcimadamore
1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Lower.java Thu Mar 14 22:54:17 2013 -0700 1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Lower.java Fri Mar 15 09:02:26 2013 +0000 1.3 @@ -3434,14 +3434,16 @@ 1.4 tree.expr = make.TypeCast(types.erasure(iterableType), tree.expr); 1.5 Symbol iterator = lookupMethod(tree.expr.pos(), 1.6 names.iterator, 1.7 - types.erasure(syms.iterableType), 1.8 + eType, 1.9 List.<Type>nil()); 1.10 VarSymbol itvar = new VarSymbol(0, names.fromString("i" + target.syntheticNameChar()), 1.11 types.erasure(iterator.type.getReturnType()), 1.12 currentMethodSym); 1.13 - JCStatement init = make. 1.14 - VarDef(itvar, 1.15 - make.App(make.Select(tree.expr, iterator))); 1.16 + 1.17 + JCStatement init = make. 1.18 + VarDef(itvar, make.App(make.Select(tree.expr, iterator) 1.19 + .setType(types.erasure(iterator.type)))); 1.20 + 1.21 Symbol hasNext = lookupMethod(tree.expr.pos(), 1.22 names.hasNext, 1.23 itvar.type,
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/test/tools/javac/T5053846/MethodRefDupInConstantPoolTest.java Fri Mar 15 09:02:26 2013 +0000 2.3 @@ -0,0 +1,91 @@ 2.4 +/* 2.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.7 + * 2.8 + * This code is free software; you can redistribute it and/or modify it 2.9 + * under the terms of the GNU General Public License version 2 only, as 2.10 + * published by the Free Software Foundation. 2.11 + * 2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 2.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 2.15 + * version 2 for more details (a copy is included in the LICENSE file that 2.16 + * accompanied this code). 2.17 + * 2.18 + * You should have received a copy of the GNU General Public License version 2.19 + * 2 along with this work; if not, write to the Free Software Foundation, 2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2.21 + * 2.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2.23 + * or visit www.oracle.com if you need additional information or have any 2.24 + * questions. 2.25 + */ 2.26 + 2.27 +/* 2.28 + * @test 2.29 + * @bug 5053846 2.30 + * @summary javac: MethodRef entries are duplicated in the constant pool 2.31 + */ 2.32 + 2.33 +import java.io.PrintWriter; 2.34 +import java.io.StringWriter; 2.35 +import java.nio.file.Paths; 2.36 +import java.util.*; 2.37 + 2.38 +public class MethodRefDupInConstantPoolTest { 2.39 + 2.40 + private static final String methodToLookFor = 2.41 + "java/util/Vector.iterator:()Ljava/util/Iterator;"; 2.42 + 2.43 + public static void main(String[] args) { 2.44 + new MethodRefDupInConstantPoolTest().run(); 2.45 + } 2.46 + 2.47 + void run() { 2.48 + check("-v", Paths.get(System.getProperty("test.classes"), 2.49 + "TestHelper1.class").toString()); 2.50 + check("-v", Paths.get(System.getProperty("test.classes"), 2.51 + "TestHelper2.class").toString()); 2.52 + } 2.53 + 2.54 + void check(String... params) { 2.55 + StringWriter s; 2.56 + String out; 2.57 + try (PrintWriter pw = new PrintWriter(s = new StringWriter())) { 2.58 + com.sun.tools.javap.Main.run(params, pw); 2.59 + out = s.toString(); 2.60 + } 2.61 + String constantPool = getConstantPool(out); 2.62 + if (constantPool.indexOf(methodToLookFor) != 2.63 + constantPool.lastIndexOf(methodToLookFor)) { 2.64 + throw new AssertionError("There is more than one entry for the method seek " + 2.65 + methodToLookFor); 2.66 + } 2.67 + } 2.68 + 2.69 + String getConstantPool(String out) { 2.70 + int start = out.indexOf("Constant pool:"); 2.71 + int end = out.indexOf("{"); 2.72 + return out.substring(start, end); 2.73 + } 2.74 +} 2.75 + 2.76 +class TestHelper1 { 2.77 + void m() { 2.78 + Vector v = new Vector(); 2.79 + Iterator iter = v.iterator(); 2.80 + while (iter.hasNext()) { 2.81 + Object o = iter.next(); 2.82 + Object o2 = o; 2.83 + } 2.84 + for (Object o: v) { 2.85 + Object o2 = o; 2.86 + } 2.87 + } 2.88 +} 2.89 + 2.90 +class TestHelper2<X extends Number & Iterable<String>> { 2.91 + void test(X x) { 2.92 + for (String s : x) { } 2.93 + } 2.94 +}