8175860: javadoc crashes with incorrect module sourcepath

Reviewed-by: jjg
This commit is contained in:
Kumar Srinivasan 2017-03-07 18:37:17 -08:00
parent 558b587367
commit 9617bfb0f6
3 changed files with 44 additions and 3 deletions

View File

@ -188,6 +188,11 @@ public class JavadocTool extends com.sun.tools.javac.main.JavaCompiler {
.classTrees(classTrees.toList())
.scanSpecifiedItems();
// abort, if errors were encountered during modules initialization
if (messager.hasErrors()) {
return null;
}
// Parse the files in the packages and subpackages to be documented
ListBuffer<JCCompilationUnit> packageTrees = new ListBuffer<>();
parse(etable.getFilesToParse(), packageTrees, false);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2017, 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
@ -184,6 +184,10 @@ public class ModuleTestBase extends TestRunner {
assertPresent(regex, Task.OutputKind.DIRECT);
}
void assertErrorNotPresent(String regex) throws Exception {
assertNotPresent(regex, Task.OutputKind.DIRECT);
}
void assertPresent(String regex, Task.OutputKind kind) throws Exception {
List<String> foundList = tb.grep(regex, currentTask.getOutputLines(kind));
if (foundList.isEmpty()) {
@ -192,6 +196,14 @@ public class ModuleTestBase extends TestRunner {
}
}
void assertNotPresent(String regex, Task.OutputKind kind) throws Exception {
List<String> foundList = tb.grep(regex, currentTask.getOutputLines(kind));
if (!foundList.isEmpty()) {
dumpDocletDiagnostics();
throw new Exception(regex + " found in: " + kind);
}
}
void dumpDocletDiagnostics() {
for (Task.OutputKind kind : Task.OutputKind.values()) {
String output = currentTask.getOutput(kind);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2017, 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 8159305 8166127
* @bug 8159305 8166127 8175860
* @summary Tests primarily the module graph computations.
* @modules
* jdk.javadoc/jdk.javadoc.internal.api
@ -38,6 +38,7 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import toolbox.*;
import toolbox.Task.Expect;
@ -92,6 +93,29 @@ public class Modules extends ModuleTestBase {
}
@Test
public void testMissingModuleWithSourcePath(Path base) throws Exception {
Path src = base.resolve("src");
Path mod = src.resolve("m1");
ModuleBuilder mb1 = new ModuleBuilder(tb, "m1");
mb1.comment("The first module.")
.exports("m1pub")
.requires("m2")
.classes("package m1pub; /** Class A */ public class A {}")
.classes("package m1pro; /** Class B */ public class B {}")
.write(src);
Path javafile = Paths.get(mod.toString(), "m1pub/A.java");
execNegativeTask("--source-path", mod.toString(),
javafile.toString());
assertErrorPresent("error: cannot access module-info");
assertErrorNotPresent("error - fatal error encountered");
}
@Test
public void testMultipleModulesAggregatedModuleOption(Path base) throws Exception {
Path src = base.resolve("src");