AnnotationProcessingWithModuleInfoInWrongPlace.java revision 3763:120957324d6e
1/* 2 * Copyright (c) 2016, 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 */ 23 24/** 25 * @test 26 * @bug 8168312 27 * @summary javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily 28 * @library /tools/lib 29 * @modules 30 * jdk.compiler/com.sun.tools.javac.api 31 * jdk.compiler/com.sun.tools.javac.main 32 * @build toolbox.ToolBox toolbox.JavacTask ModuleTestBase 33 * @run main AnnotationProcessingWithModuleInfoInWrongPlace 34 */ 35 36import java.nio.file.Files; 37import java.nio.file.Path; 38import java.util.Set; 39 40import javax.annotation.processing.AbstractProcessor; 41import javax.annotation.processing.RoundEnvironment; 42import javax.annotation.processing.SupportedAnnotationTypes; 43import javax.lang.model.SourceVersion; 44import javax.lang.model.element.TypeElement; 45 46import toolbox.JavacTask; 47import toolbox.Task; 48 49public class AnnotationProcessingWithModuleInfoInWrongPlace extends ModuleTestBase { 50 51 public static void main(String... args) throws Exception { 52 new AnnotationProcessingWithModuleInfoInWrongPlace().runTests(); 53 } 54 55 @Test 56 public void testModuleInfoInWrongPlace(Path base) throws Exception { 57 Path moduleSrc = base.resolve("module-src"); 58 Path m = moduleSrc.resolve("m"); 59 60 Path classes = base.resolve("classes"); 61 62 Files.createDirectories(classes); 63 64 tb.writeJavaFiles(m, "module m {}"); 65 66 Path mi = m.resolve("module-info.java"); 67 Path f = m.resolve("F.java"); 68 69 tb.moveFile(mi, f); 70 71 String log = new JavacTask(tb) 72 .options("-XDrawDiagnostics", 73 "--module-source-path", moduleSrc.toString(), 74 "-processor", AP.class.getName()) 75 .outdir(classes) 76 .files(findJavaFiles(moduleSrc)) 77 .run(Task.Expect.FAIL) 78 .writeAll() 79 .getOutput(Task.OutputKind.DIRECT); 80 81 82 if (!log.contains("F.java:1:1: compiler.err.module.decl.sb.in.module-info.java")) 83 throw new AssertionError("Unexpected output: " + log); 84 } 85 86 @SupportedAnnotationTypes("*") 87 public static final class AP extends AbstractProcessor { 88 89 @Override 90 public boolean process(Set<? extends TypeElement> annot, RoundEnvironment env) { 91 return false; 92 } 93 94 @Override 95 public SourceVersion getSupportedSourceVersion() { 96 return SourceVersion.latest(); 97 } 98 } 99} 100