author | sadayapalam |
Mon, 06 Feb 2017 18:14:51 +0530 | |
changeset 43584 | 63e67712246b |
parent 41999 | dbf796210eff |
permissions | -rw-r--r-- |
41999
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
1 |
/* |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
2 |
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
4 |
* |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
8 |
* |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
13 |
* accompanied this code). |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
14 |
* |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
18 |
* |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
21 |
* questions. |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
22 |
*/ |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
23 |
|
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
24 |
/** |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
25 |
* @test |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
26 |
* @bug 8168312 |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
27 |
* @summary javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
28 |
* @library /tools/lib |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
29 |
* @modules |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
30 |
* jdk.compiler/com.sun.tools.javac.api |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
31 |
* jdk.compiler/com.sun.tools.javac.main |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
32 |
* @build toolbox.ToolBox toolbox.JavacTask ModuleTestBase |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
33 |
* @run main AnnotationProcessingWithModuleInfoInWrongPlace |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
34 |
*/ |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
35 |
|
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
36 |
import java.nio.file.Files; |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
37 |
import java.nio.file.Path; |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
38 |
import java.util.Set; |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
39 |
|
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
40 |
import javax.annotation.processing.AbstractProcessor; |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
41 |
import javax.annotation.processing.RoundEnvironment; |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
42 |
import javax.annotation.processing.SupportedAnnotationTypes; |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
43 |
import javax.lang.model.SourceVersion; |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
44 |
import javax.lang.model.element.TypeElement; |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
45 |
|
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
46 |
import toolbox.JavacTask; |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
47 |
import toolbox.Task; |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
48 |
|
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
49 |
public class AnnotationProcessingWithModuleInfoInWrongPlace extends ModuleTestBase { |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
50 |
|
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
51 |
public static void main(String... args) throws Exception { |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
52 |
new AnnotationProcessingWithModuleInfoInWrongPlace().runTests(); |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
53 |
} |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
54 |
|
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
55 |
@Test |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
56 |
public void testModuleInfoInWrongPlace(Path base) throws Exception { |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
57 |
Path moduleSrc = base.resolve("module-src"); |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
58 |
Path m = moduleSrc.resolve("m"); |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
59 |
|
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
60 |
Path classes = base.resolve("classes"); |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
61 |
|
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
62 |
Files.createDirectories(classes); |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
63 |
|
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
64 |
tb.writeJavaFiles(m, "module m {}"); |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
65 |
|
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
66 |
Path mi = m.resolve("module-info.java"); |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
67 |
Path f = m.resolve("F.java"); |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
68 |
|
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
69 |
tb.moveFile(mi, f); |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
70 |
|
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
71 |
String log = new JavacTask(tb) |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
72 |
.options("-XDrawDiagnostics", |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
73 |
"--module-source-path", moduleSrc.toString(), |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
74 |
"-processor", AP.class.getName()) |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
75 |
.outdir(classes) |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
76 |
.files(findJavaFiles(moduleSrc)) |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
77 |
.run(Task.Expect.FAIL) |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
78 |
.writeAll() |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
79 |
.getOutput(Task.OutputKind.DIRECT); |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
80 |
|
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
81 |
|
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
82 |
if (!log.contains("F.java:1:1: compiler.err.module.decl.sb.in.module-info.java")) |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
83 |
throw new AssertionError("Unexpected output: " + log); |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
84 |
} |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
85 |
|
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
86 |
@SupportedAnnotationTypes("*") |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
87 |
public static final class AP extends AbstractProcessor { |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
88 |
|
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
89 |
@Override |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
90 |
public boolean process(Set<? extends TypeElement> annot, RoundEnvironment env) { |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
91 |
return false; |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
92 |
} |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
93 |
|
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
94 |
@Override |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
95 |
public SourceVersion getSupportedSourceVersion() { |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
96 |
return SourceVersion.latest(); |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
97 |
} |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
98 |
} |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
diff
changeset
|
99 |
} |