8217868: Crash for overlap between source path and patch module path

When analyzing implicit files, do not look for containing module, but rather use the already known one.

Reviewed-by: jjg
This commit is contained in:
Jan Lahoda 2019-03-04 10:19:35 +01:00
parent 0d13646cbf
commit 76c916516c
3 changed files with 30 additions and 13 deletions
src
jdk.compiler/share/classes/com/sun/tools/javac/comp
jdk.javadoc/share/classes/jdk/javadoc/internal/tool
test/langtools/tools/javac/modules

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 2019, 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
@ -504,12 +504,8 @@ public class Modules extends JCTree.Visitor {
module.completer = sym -> completeModule((ModuleSymbol) sym);
} else {
Assert.check(rootModules.isEmpty());
String moduleOverride = singleModuleOverride(trees);
if (moduleOverride != null) {
module = moduleFinder.findModule(names.fromString(moduleOverride));
} else {
module = defaultModule;
}
Assert.checkNonNull(c);
module = c.packge().modle;
rootModules.add(module);
}
@ -1796,6 +1792,7 @@ public class Modules extends JCTree.Visitor {
public void newRound() {
allModules = null;
rootModules = null;
defaultModule = null;
warnedMissing.clear();
}

@ -197,9 +197,11 @@ public class JavadocTool extends com.sun.tools.javac.main.JavaCompiler {
}
// Parse the files in the packages and subpackages to be documented
ListBuffer<JCCompilationUnit> packageTrees = new ListBuffer<>();
parse(etable.getFilesToParse(), packageTrees, false);
modules.enter(packageTrees.toList(), null);
ListBuffer<JCCompilationUnit> allTrees = new ListBuffer<>();
allTrees.addAll(classTrees);
parse(etable.getFilesToParse(), allTrees, false);
modules.newRound();
modules.initModules(allTrees.toList());
if (messager.hasErrors()) {
return null;
@ -207,7 +209,7 @@ public class JavadocTool extends com.sun.tools.javac.main.JavaCompiler {
// Enter symbols for all files
toolEnv.notice("main.Building_tree");
javadocEnter.main(classTrees.toList().appendList(packageTrees));
javadocEnter.main(allTrees.toList());
if (messager.hasErrors()) {
return null;

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2019, 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
@ -23,7 +23,7 @@
/*
* @test
* @bug 8160489
* @bug 8160489 8217868
* @summary tests for --patch-modules
* @library /tools/lib
* @modules
@ -192,5 +192,23 @@ public class PatchModulesTest extends ModuleTestBase {
throw new AssertionError();
}
}
@Test
public void testPatchModuleSourcePathClash(Path base) throws Exception {
Path src = base.resolve("src");
tb.writeJavaFiles(src,
"module m { uses test.Test; }",
"package test; public class Test { }");
Path classes = base.resolve("classes");
tb.createDirectories(classes);
new toolbox.JavacTask(tb)
.options("--patch-module", "other=" + src.toString(),
"-sourcepath", src.toString())
.outdir(classes)
.files(findJavaFiles(src.resolve("module-info.java")))
.run()
.writeAll();
}
}