author | jjg |
Thu, 31 Mar 2016 15:20:50 -0700 | |
changeset 36778 | e04318f39f92 |
parent 36526 | 3b41f1c69604 |
permissions | -rw-r--r-- |
32059
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
1 |
/* |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
2 |
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. |
32059
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
4 |
* |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
8 |
* |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
13 |
* accompanied this code). |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
14 |
* |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
18 |
* |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
21 |
* questions. |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
22 |
*/ |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
23 |
|
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
24 |
/** |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
25 |
* @test |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
26 |
* @bug 8131915 |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
27 |
* @summary Verify that CompletionFailure thrown during listing of import content is handled properly. |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
28 |
* @library /tools/lib |
36526 | 29 |
* @modules jdk.compiler/com.sun.tools.javac.api |
30 |
* jdk.compiler/com.sun.tools.javac.main |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
31 |
* @build toolbox.ToolBox toolbox.JavacTask |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
32 |
* @run main CompletionFailureDuringImport |
32059
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
33 |
*/ |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
34 |
|
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
35 |
import java.nio.file.Files; |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
36 |
import java.nio.file.Paths; |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
37 |
import java.util.Arrays; |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
38 |
import java.util.List; |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
39 |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
40 |
import toolbox.JavacTask; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
41 |
import toolbox.Task; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
42 |
import toolbox.ToolBox; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
43 |
|
32059
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
44 |
public class CompletionFailureDuringImport { |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
45 |
public static void main(String... args) throws Exception { |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
46 |
new CompletionFailureDuringImport().run(); |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
47 |
} |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
48 |
|
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
49 |
ToolBox tb = new ToolBox(); |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
50 |
|
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
51 |
void run() throws Exception { |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
52 |
new JavacTask(tb) |
32059
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
53 |
.outdir(".") |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
54 |
.sources("package p; public class Super { public static final int I = 0; }", |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
55 |
"package p; public class Sub extends Super { }") |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
56 |
.run() |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
57 |
.writeAll(); |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
58 |
|
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
59 |
Files.delete(Paths.get(".", "p", "Super.class")); |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
60 |
|
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
61 |
doTest("import static p.Sub.*;", |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
62 |
"", |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
63 |
"Test.java:1:1: compiler.err.cant.access: p.Super, (compiler.misc.class.file.not.found: p.Super)", |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
64 |
"1 error"); |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
65 |
doTest("import static p.Sub.I;", |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
66 |
"", |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
67 |
"Test.java:1:1: compiler.err.cant.access: p.Super, (compiler.misc.class.file.not.found: p.Super)", |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
68 |
"1 error"); |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
69 |
doTest("import static p.Sub.*;", |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
70 |
"int i = I;", |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
71 |
"Test.java:1:1: compiler.err.cant.access: p.Super, (compiler.misc.class.file.not.found: p.Super)", |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
72 |
"Test.java:1:52: compiler.err.cant.resolve.location: kindname.variable, I, , , (compiler.misc.location: kindname.class, Test, null)", |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
73 |
"2 errors"); |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
74 |
doTest("import static p.Sub.I;", |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
75 |
"int i = I;", |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
76 |
"Test.java:1:1: compiler.err.cant.access: p.Super, (compiler.misc.class.file.not.found: p.Super)", |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
77 |
"Test.java:1:52: compiler.err.cant.resolve.location: kindname.variable, I, , , (compiler.misc.location: kindname.class, Test, null)", |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
78 |
"2 errors"); |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
79 |
} |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
80 |
|
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
81 |
void doTest(String importText, String useText, String... expectedOutput) { |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
82 |
List<String> log = new JavacTask(tb) |
32059
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
83 |
.classpath(".") |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
84 |
.sources(importText + " public class Test { " + useText + " }") |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
85 |
.options("-XDrawDiagnostics") |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
86 |
.run(Task.Expect.FAIL) |
32059
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
87 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
88 |
.getOutputLines(Task.OutputKind.DIRECT); |
32059
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
89 |
|
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
90 |
if (!log.equals(Arrays.asList(expectedOutput))) { |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
91 |
throw new AssertionError("Unexpected output: " + log); |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
92 |
} |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
93 |
} |
ea04f56aeacd
8131915: CompletionFailure during import listing crashes javac
jlahoda
parents:
diff
changeset
|
94 |
} |