8158224: NullPointerException in com.sun.tools.javac.comp.Modules.checkCyclicDependencies when module missing
Reviewed-by: jlahoda
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Modules.java Wed Jul 27 07:07:10 2016 -0700
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Modules.java Thu Jul 28 10:13:34 2016 +0530
@@ -757,7 +757,9 @@
@Override
public void visitRequires(JCRequires tree) {
- msym.directives = msym.directives.prepend(tree.directive);
+ if (tree.directive != null) {
+ msym.directives = msym.directives.prepend(tree.directive);
+ }
}
@Override
@@ -1214,9 +1216,9 @@
private void checkCyclicDependencies(JCModuleDecl mod) {
for (JCDirective d : mod.directives) {
- if (!d.hasTag(Tag.REQUIRES))
+ JCRequires rd;
+ if (!d.hasTag(Tag.REQUIRES) || (rd = (JCRequires) d).directive == null)
continue;
- JCRequires rd = (JCRequires) d;
Set<ModuleSymbol> nonSyntheticDeps = new HashSet<>();
List<ModuleSymbol> queue = List.of(rd.directive.module);
while (queue.nonEmpty()) {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/modules/T8158224/Processor.java Thu Jul 28 10:13:34 2016 +0530
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.util.Set;
+import javax.annotation.processing.AbstractProcessor;
+import javax.annotation.processing.RoundEnvironment;
+import javax.annotation.processing.SupportedAnnotationTypes;
+import javax.annotation.processing.SupportedSourceVersion;
+import javax.lang.model.element.TypeElement;
+import javax.lang.model.SourceVersion;
+
+@SupportedAnnotationTypes("Blah")
+@SupportedSourceVersion(SourceVersion.RELEASE_6)
+public class Processor extends AbstractProcessor {
+
+ @Override
+ public boolean process(Set<? extends TypeElement> tE, RoundEnvironment env) {
+ return true;
+ }
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/modules/T8158224/T8158224.java Thu Jul 28 10:13:34 2016 +0530
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8158224
+ * @summary NullPointerException in com.sun.tools.javac.comp.Modules.checkCyclicDependencies when module missing
+ * @build Processor
+ * @compile/fail/ref=T8158224.out -XDrawDiagnostics -processor Processor mods/foo/module-info.java
+ */
+
+// No code here, this file is just to host test description.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/modules/T8158224/T8158224.out Thu Jul 28 10:13:34 2016 +0530
@@ -0,0 +1,2 @@
+module-info.java:4:14: compiler.err.module.not.found: nonexistent
+1 error
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/modules/T8158224/mods/foo/module-info.java Thu Jul 28 10:13:34 2016 +0530
@@ -0,0 +1,5 @@
+/* /nodynamiccopyright/ */
+
+module foo {
+ requires nonexistent;
+}