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
jjg@930 | 1 | /* |
katleman@1013 | 2 | * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. |
jjg@930 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
jjg@930 | 4 | * |
jjg@930 | 5 | * This code is free software; you can redistribute it and/or modify it |
jjg@930 | 6 | * under the terms of the GNU General Public License version 2 only, as |
jjg@930 | 7 | * published by the Free Software Foundation. |
jjg@930 | 8 | * |
jjg@930 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
jjg@930 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
jjg@930 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
jjg@930 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
jjg@930 | 13 | * accompanied this code). |
jjg@930 | 14 | * |
jjg@930 | 15 | * You should have received a copy of the GNU General Public License version |
jjg@930 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
jjg@930 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
jjg@930 | 18 | * |
jjg@930 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
jjg@930 | 20 | * or visit www.oracle.com if you need additional information or have any |
jjg@930 | 21 | * questions. |
jjg@930 | 22 | */ |
jjg@930 | 23 | |
jjg@930 | 24 | /* |
jjg@930 | 25 | * @test |
jjg@930 | 26 | * @bug 7026509 |
jjg@930 | 27 | * @summary Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations |
jjg@930 | 28 | */ |
jjg@930 | 29 | |
jjg@930 | 30 | import java.io.*; |
jjg@930 | 31 | import java.util.*; |
jjg@930 | 32 | import javax.tools.*; |
jjg@930 | 33 | import javax.tools.JavaCompiler.CompilationTask; |
jjg@930 | 34 | import com.sun.source.util.*; |
jjg@930 | 35 | |
jjg@930 | 36 | public class TestJavacTask_Lock { |
jjg@930 | 37 | public static void main(String... args) throws Exception { |
jjg@930 | 38 | new TestJavacTask_Lock().run(); |
jjg@930 | 39 | } |
jjg@930 | 40 | |
jjg@930 | 41 | enum MethodKind { |
jjg@930 | 42 | CALL { |
jjg@930 | 43 | int test(CompilationTask t) { |
jjg@930 | 44 | boolean ok = t.call(); |
jjg@930 | 45 | if (!ok) |
jjg@930 | 46 | throw new Error("compilation failed"); |
jjg@930 | 47 | return 1; |
jjg@930 | 48 | } |
jjg@930 | 49 | }, |
jjg@930 | 50 | PARSE { |
jjg@930 | 51 | int test(CompilationTask t) { |
jjg@930 | 52 | try { |
jjg@930 | 53 | ((JavacTask) t).parse(); |
jjg@930 | 54 | return 1; |
jjg@930 | 55 | } catch (IOException ex) { |
jjg@930 | 56 | throw new Error(ex); |
jjg@930 | 57 | } |
jjg@930 | 58 | } |
jjg@930 | 59 | |
jjg@930 | 60 | }; |
jjg@930 | 61 | abstract int test(CompilationTask t); |
jjg@930 | 62 | } |
jjg@930 | 63 | |
jjg@930 | 64 | JavaCompiler comp; |
jjg@930 | 65 | StandardJavaFileManager fm; |
jjg@930 | 66 | |
jjg@930 | 67 | void run() throws Exception { |
jjg@930 | 68 | comp = ToolProvider.getSystemJavaCompiler(); |
jjg@930 | 69 | fm = comp.getStandardFileManager(null, null, null); |
jjg@930 | 70 | |
jjg@930 | 71 | for (MethodKind first: MethodKind.values()) { |
jjg@930 | 72 | for (MethodKind second: MethodKind.values()) { |
jjg@930 | 73 | test(first, second); |
jjg@930 | 74 | } |
jjg@930 | 75 | } |
jjg@930 | 76 | |
jjg@930 | 77 | if (errors > 0) |
jjg@930 | 78 | throw new Exception(errors + " errors found"); |
jjg@930 | 79 | } |
jjg@930 | 80 | |
jjg@930 | 81 | void test(MethodKind first, MethodKind second) { |
jjg@930 | 82 | System.err.println("test: " + first + ", " + second); |
jjg@930 | 83 | File testSrc = new File(System.getProperty("test.src")); |
jjg@930 | 84 | String thisClassName = TestJavacTask_Lock.class.getName(); |
jjg@930 | 85 | Iterable<? extends JavaFileObject> files = |
jjg@930 | 86 | fm.getJavaFileObjects(new File(testSrc, thisClassName + ".java")); |
jjg@930 | 87 | File tmpDir = new File(first + "_" + second); |
jjg@930 | 88 | tmpDir.mkdirs(); |
jjg@930 | 89 | List<String> options = Arrays.asList( "-d", tmpDir.getPath() ); |
jjg@930 | 90 | CompilationTask t = comp.getTask(null, fm, null, options, null, files); |
jjg@930 | 91 | |
jjg@930 | 92 | try { |
jjg@930 | 93 | first.test(t); |
jjg@930 | 94 | second.test(t); |
jjg@930 | 95 | error("No exception thrown"); |
jjg@930 | 96 | } catch (IllegalStateException e) { |
jjg@930 | 97 | System.err.println("Expected exception caught: " + e); |
jjg@930 | 98 | } catch (Exception e) { |
jjg@930 | 99 | error("Unexpected exception caught: " + e); |
jjg@930 | 100 | e.printStackTrace(System.err); |
jjg@930 | 101 | } |
jjg@930 | 102 | |
jjg@930 | 103 | } |
jjg@930 | 104 | |
jjg@930 | 105 | void error(String msg) { |
jjg@930 | 106 | System.err.println("Error: " + msg); |
jjg@930 | 107 | errors++; |
jjg@930 | 108 | } |
jjg@930 | 109 | |
jjg@930 | 110 | int errors; |
jjg@930 | 111 | } |