Mon, 01 Jul 2013 14:57:03 +0100
7034798: Ambiguity error for abstract method call is too eager
Summary: Javac should wait and see if ambiguous methods can be reconciled at the end of an overload resolution round
Reviewed-by: jjg, vromero
1 /*
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
24 /*
25 * @test
26 * @bug 7008643
27 * @summary inlined finally clauses confuse debuggers
28 * @library /tools/javac/lib
29 * @build ToolBox
30 * @run main InlinedFinallyConfuseDebuggersTest
31 */
33 import java.io.File;
34 import java.nio.file.Paths;
36 import com.sun.tools.classfile.ClassFile;
37 import com.sun.tools.classfile.Code_attribute;
38 import com.sun.tools.classfile.LineNumberTable_attribute;
39 import com.sun.tools.classfile.Method;
40 import com.sun.tools.javac.util.Assert;
42 public class InlinedFinallyConfuseDebuggersTest {
44 static final String testSource =
45 /* 01 */ "public class InlinedFinallyTest {\n" +
46 /* 02 */ " void lookForThisMethod(int value) {\n" +
47 /* 03 */ " try {\n" +
48 /* 04 */ " if (value > 0) {\n" +
49 /* 05 */ " System.out.println(\"if\");\n" +
50 /* 06 */ " return;\n" +
51 /* 07 */ " }\n" +
52 /* 08 */ " } finally {\n" +
53 /* 09 */ " System.out.println(\"finally\");\n" +
54 /* 10 */ " }\n" +
55 /* 11 */ " }\n" +
56 /* 12 */ "}";
58 static final int[][] expectedLNT = {
59 // {line-number, start-pc},
60 {4, 0}, //if (value > 0) {
61 {5, 4}, // System.out.println("if");
62 {9, 12}, //System.out.println("finally");
63 {6, 20}, // return;
64 {9, 21}, //System.out.println("finally");
65 {10, 29},
66 {9, 32}, //System.out.println("finally");
67 {11, 43},
68 };
70 static final String methodToLookFor = "lookForThisMethod";
72 public static void main(String[] args) throws Exception {
73 new InlinedFinallyConfuseDebuggersTest().run();
74 }
76 void run() throws Exception {
77 compileTestClass();
78 checkClassFile(new File(Paths.get(System.getProperty("user.dir"),
79 "InlinedFinallyTest.class").toUri()), methodToLookFor);
80 }
82 void compileTestClass() throws Exception {
83 ToolBox.JavaToolArgs javacSuccessArgs =
84 new ToolBox.JavaToolArgs().setSources(testSource);
85 ToolBox.javac(javacSuccessArgs);
86 }
88 void checkClassFile(final File cfile, String methodToFind) throws Exception {
89 ClassFile classFile = ClassFile.read(cfile);
90 boolean methodFound = false;
91 for (Method method : classFile.methods) {
92 if (method.getName(classFile.constant_pool).equals(methodToFind)) {
93 methodFound = true;
94 Code_attribute code = (Code_attribute) method.attributes.get("Code");
95 LineNumberTable_attribute lnt =
96 (LineNumberTable_attribute) code.attributes.get("LineNumberTable");
97 Assert.check(lnt.line_number_table_length == expectedLNT.length,
98 "The LineNumberTable found has a length different to the expected one");
99 int i = 0;
100 for (LineNumberTable_attribute.Entry entry: lnt.line_number_table) {
101 Assert.check(entry.line_number == expectedLNT[i][0] &&
102 entry.start_pc == expectedLNT[i][1],
103 "LNT entry at pos " + i + " differ from expected." +
104 "Found " + entry.line_number + ":" + entry.start_pc +
105 ". Expected " + expectedLNT[i][0] + ":" + expectedLNT[i][1]);
106 i++;
107 }
108 }
109 }
110 Assert.check(methodFound, "The seek method was not found");
111 }
113 void error(String msg) {
114 throw new AssertionError(msg);
115 }
117 }