changeset 44181:2075fecdcce1

8175860: javadoc crashes with incorrect module sourcepath Reviewed-by: jjg
author ksrini
date Tue, 07 Mar 2017 18:37:17 -0800
parents 207e05e0d9ad
children ce2f0cbc81b9
files langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/JavadocTool.java langtools/test/jdk/javadoc/tool/modules/ModuleTestBase.java langtools/test/jdk/javadoc/tool/modules/Modules.java
diffstat 3 files changed, 44 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/JavadocTool.java	Tue Mar 07 15:20:43 2017 -0800
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/JavadocTool.java	Tue Mar 07 18:37:17 2017 -0800
@@ -188,6 +188,11 @@
                     .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);
--- a/langtools/test/jdk/javadoc/tool/modules/ModuleTestBase.java	Tue Mar 07 15:20:43 2017 -0800
+++ b/langtools/test/jdk/javadoc/tool/modules/ModuleTestBase.java	Tue Mar 07 18:37:17 2017 -0800
@@ -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 @@
         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 @@
         }
     }
 
+    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);
--- a/langtools/test/jdk/javadoc/tool/modules/Modules.java	Tue Mar 07 15:20:43 2017 -0800
+++ b/langtools/test/jdk/javadoc/tool/modules/Modules.java	Tue Mar 07 18:37:17 2017 -0800
@@ -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;
@@ -93,6 +94,29 @@
     }
 
     @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");