Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
8241519: javac crashes with wrong module-info.class in module path
If module-info.class is broken, mark the corresponding ModuleSymbol as erroneous.

Reviewed-by: jjg
  • Loading branch information
Jan Lahoda committed Jun 2, 2020
1 parent 1adecc8 commit 04ad75e788a062f87538c83a99f26e26bdf26f5a
Showing with 60 additions and 7 deletions.
  1. +18 −6 src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Modules.java
  2. +42 −1 test/langtools/tools/javac/modules/EdgeCases.java
@@ -630,15 +630,19 @@ public void complete(Symbol sym) throws CompletionFailure {

if (msym.kind == ERR) {
//make sure the module is initialized:
msym.directives = List.nil();
msym.exports = List.nil();
msym.provides = List.nil();
msym.requires = List.nil();
msym.uses = List.nil();
initErrModule(msym);
} else if ((msym.flags_field & Flags.AUTOMATIC_MODULE) != 0) {
setupAutomaticModule(msym);
} else {
msym.module_info.complete();
try {
msym.module_info.complete();
} catch (CompletionFailure cf) {
msym.kind = ERR;
//make sure the module is initialized:
initErrModule(msym);
completeModule(msym);
throw cf;
}
}

// If module-info comes from a .java file, the underlying
@@ -653,6 +657,14 @@ public void complete(Symbol sym) throws CompletionFailure {
}
}

private void initErrModule(ModuleSymbol msym) {
msym.directives = List.nil();
msym.exports = List.nil();
msym.provides = List.nil();
msym.requires = List.nil();
msym.uses = List.nil();
}

@Override
public String toString() {
return "mainCompleter";
@@ -23,7 +23,7 @@

/*
* @test
* @bug 8154283 8167320 8171098 8172809 8173068 8173117 8176045 8177311
* @bug 8154283 8167320 8171098 8172809 8173068 8173117 8176045 8177311 8241519
* @summary tests for multi-module mode compilation
* @library /tools/lib
* @modules
@@ -996,4 +996,45 @@ public void testDependOnUnnamedAccessibility(Path base) throws Exception {
.writeAll();
}

@Test
public void testMisnamedModuleInfoClass(Path base) throws Exception {
Path src = base.resolve("src");
Path a = src.resolve("a");
tb.writeJavaFiles(a,
"module a {}");
Path b = src.resolve("b");
tb.writeJavaFiles(b,
"module b { uses com.example.c; }");
Path classes = base.resolve("classes");
tb.createDirectories(classes);
Path aClasses = classes.resolve("x");
tb.createDirectories(aClasses);

new JavacTask(tb)
.outdir(aClasses)
.files(findJavaFiles(a))
.run()
.writeAll();

Path bClasses = classes.resolve("b");
tb.createDirectories(bClasses);

List<String> log;

log = new JavacTask(tb)
.outdir(bClasses)
.options("-p", classes.toString(),
"-XDrawDiagnostics")
.files(findJavaFiles(b))
.run(Task.Expect.FAIL)
.writeAll()
.getOutputLines(Task.OutputKind.DIRECT);

List<String> expected = List.of("module-info.java:1:28: compiler.err.doesnt.exist: com.example",
"1 error");

if (!expected.equals(log))
throw new Exception("expected output not found: " + log);
}

}

0 comments on commit 04ad75e

Please sign in to comment.