8172809: Error compiling javafx modules after fix for JDK-8169197
Summary: Properly stripping broken requires from ModuleSymbols.
Reviewed-by: jjg, mcimadamore
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Modules.java Fri Jan 20 13:20:42 2017 +0100
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Modules.java Fri Jan 20 15:32:03 2017 +0100
@@ -978,7 +978,7 @@
@Override
public void visitRequires(JCRequires tree) {
- if (tree.directive != null) {
+ if (tree.directive != null && allModules().contains(tree.directive.module)) {
chk.checkDeprecated(tree.moduleName.pos(), msym, tree.directive.module);
msym.directives = msym.directives.prepend(tree.directive);
}
@@ -1263,7 +1263,6 @@
msym.requires = msym.requires.appendList(List.from(addReads.getOrDefault(msym, Collections.emptySet())));
List<RequiresDirective> requires = msym.requires;
- List<RequiresDirective> previous = null;
while (requires.nonEmpty()) {
if (!allModules().contains(requires.head.module)) {
@@ -1278,13 +1277,7 @@
} else {
Assert.check((msym.flags() & Flags.AUTOMATIC_MODULE) == 0);
}
- if (previous != null) {
- previous.tail = requires.tail;
- } else {
- msym.requires.tail = requires.tail;
- }
- } else {
- previous = requires;
+ msym.requires = List.filter(msym.requires, requires.head);
}
requires = requires.tail;
}
--- a/langtools/test/tools/javac/modules/EdgeCases.java Fri Jan 20 13:20:42 2017 +0100
+++ b/langtools/test/tools/javac/modules/EdgeCases.java Fri Jan 20 15:32:03 2017 +0100
@@ -23,13 +23,14 @@
/*
* @test
- * @bug 8154283 8167320 8171098
+ * @bug 8154283 8167320 8171098 8172809
* @summary tests for multi-module mode compilation
* @library /tools/lib
* @modules
* jdk.compiler/com.sun.tools.javac.api
* jdk.compiler/com.sun.tools.javac.code
* jdk.compiler/com.sun.tools.javac.main
+ * jdk.compiler/com.sun.tools.javac.util
* @build toolbox.ToolBox toolbox.JarTask toolbox.JavacTask ModuleTestBase
* @run main EdgeCases
*/
@@ -44,7 +45,16 @@
import java.util.Objects;
import java.util.Set;
+import javax.annotation.processing.AbstractProcessor;
+import javax.annotation.processing.RoundEnvironment;
+import javax.annotation.processing.SupportedAnnotationTypes;
+import javax.annotation.processing.SupportedOptions;
+import javax.lang.model.SourceVersion;
import javax.lang.model.element.Element;
+import javax.lang.model.element.ModuleElement;
+import javax.lang.model.element.ModuleElement.RequiresDirective;
+import javax.lang.model.element.TypeElement;
+import javax.lang.model.util.ElementFilter;
import javax.tools.JavaCompiler;
import javax.tools.JavaFileObject;
import javax.tools.StandardJavaFileManager;
@@ -486,6 +496,85 @@
}
@Test
+ public void testStripUnknownRequired(Path base) throws Exception {
+ Path src = base.resolve("src");
+ Path src_m1 = src.resolve("m1x");
+ tb.writeJavaFiles(src_m1,
+ "module m1x { }");
+ Path src_m2 = src.resolve("m2x");
+ tb.writeJavaFiles(src_m2,
+ "module m2x { }");
+ Path src_m3 = src.resolve("m3x");
+ tb.writeJavaFiles(src_m3,
+ "module m3x { }");
+ Path src_m4 = src.resolve("m4x");
+ tb.writeJavaFiles(src_m4,
+ "module m4x { }");
+ Path src_test = src.resolve("test");
+ tb.writeJavaFiles(src_test,
+ "module test { requires m1x; requires m2x; requires java.base; requires m3x; requires m4x; }");
+ Path src_compile = src.resolve("compile");
+ tb.writeJavaFiles(src_compile,
+ "module compile { exports p to test; }",
+ "package p; public class Test { }");
+ Path classes = base.resolve("classes");
+ tb.createDirectories(classes);
+
+ List<String> log = new JavacTask(tb)
+ .options("-processor", ListRequires.class.getName(),
+ "--module-source-path", src.toString(),
+ "--limit-modules", "compile",
+ "-XDaccessInternalAPI=true")
+ .outdir(classes)
+ .files(findJavaFiles(src_compile))
+ .run(Expect.FAIL)
+ .writeAll()
+ .getOutputLines(Task.OutputKind.STDOUT);
+
+ List<String> expected = Arrays.asList(
+ "from directives:",
+ "java.base",
+ "from requires:",
+ "java.base"
+ );
+ if (!Objects.equals(log, expected))
+ throw new AssertionError("Unexpected output: " + log);
+ }
+
+ @SupportedAnnotationTypes("*")
+ @SupportedOptions("expectedEnclosedElements")
+ public static final class ListRequires extends AbstractProcessor {
+
+ private int round;
+
+ @Override
+ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
+ if (round++ == 0) {
+ ModuleElement compileE = processingEnv.getElementUtils().getModuleElement("compile");
+ ModuleElement testE = ElementFilter.exportsIn(compileE.getDirectives()).get(0).getTargetModules().get(0);
+
+ System.out.println("from directives:");
+ for (RequiresDirective rd : ElementFilter.requiresIn(testE.getDirectives())) {
+ System.out.println(rd.getDependency().getSimpleName());
+ }
+
+ System.out.println("from requires:");
+ for (RequiresDirective rd : ((ModuleSymbol) testE).requires) {
+ System.out.println(rd.getDependency().getSimpleName());
+ }
+ }
+
+ return false;
+ }
+
+ @Override
+ public SourceVersion getSupportedSourceVersion() {
+ return SourceVersion.latest();
+ }
+
+ }
+
+ @Test
public void testOnDemandCompletionModuleInfoJava(Path base) throws Exception {
Path src = base.resolve("src");
Path src_m1 = src.resolve("m1x");