Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8187422

javadoc errors if invalid source files coexist with documented source files

XMLWordPrintable

      FULL PRODUCT VERSION :
      openjdk version "9-Ubuntu"
      OpenJDK Runtime Environment (build 9-Ubuntu+0-9b181-4)
      OpenJDK 64-Bit Server VM (build 9-Ubuntu+0-9b181-4, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Linux astoria 4.10.0-32-generic #36-Ubuntu SMP Tue Aug 8 12:10:06 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      javadoc has started validating source files that it shouldn't be reading. If these are invalid, then javadoc crashes with an exception. This is unexpected, and a regression from Java 8.

      With source files in a layout like the following, where "Valid" is a valid Java source file, and "Invalid.java" is an invalid Java source file:

      com/example/Valid.java
      com/example/Invalid.java

      ... running "javadoc com/example/Valid.java" used to succeed, but now fails with a big exception, starting with:

      javadoc: error - An exception occurred while building a component: Contents
      (com.sun.tools.javac.code.ClassFinder$BadClassFile: bad source file: ./com/example/Invalid.java
        file does not contain class com.example.Invalid


      This happens when people litter test or example code around, e.g. Invalid.java contains:

      /* no package line */
      class Invalid {}


      REGRESSION. Last worked in version 8u131

      ADDITIONAL REGRESSION INFORMATION:
      openjdk version "1.8.0_131"
      OpenJDK Runtime Environment (build 1.8.0_131-8u131-b11-2ubuntu1.16.04.3-b11)
      OpenJDK 64-Bit Server VM (build 25.131-b11, mixed mode)


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      # This bash script creates some source files:

      mkdir -p a

      # first, a valid class:
      echo 'package a; public class B {}' > a/B.java

      # then, an invalid one:
      echo '/* no package */ class RealClassName {}' > a/RealFileName.java

      # and tries to generate the javadoc for just the valid class:
      javadoc a/B.java


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      On Java 8, the invalid files are ignored; the doc is generated for just "B".

      ACTUAL -
      On Java 9, javadoc fails, and the big exception is output.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      javadoc: error - An exception occurred while building a component: Contents
      (com.sun.tools.javac.code.ClassFinder$BadClassFile: bad source file: ./a/C.java
        file does not contain class a.C
        Please remove or make sure it appears in the correct subdirectory of the sourcepath.)
      Please file a bug against the javadoc tool via the Java bug reporting page
      (http://bugreport.java.com) after checking the Bug Database (http://bugs.java.com)
      for duplicates. Include error messages and the following diagnostic in your report. Thank you.
      com.sun.tools.javac.code.ClassFinder$BadClassFile: bad source file: ./a/C.java
        file does not contain class a.C
        Please remove or make sure it appears in the correct subdirectory of the sourcepath.
      at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.readSourceFile(JavaCompiler.java:856)
      at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.readSourceFile(JavaCompiler.java:783)
      at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.lambda$new$0(JavaCompiler.java:343)
      at jdk.compiler/com.sun.tools.javac.code.ClassFinder.fillIn(ClassFinder.java:352)
      at jdk.compiler/com.sun.tools.javac.code.ClassFinder.complete(ClassFinder.java:285)
      at jdk.compiler/com.sun.tools.javac.code.Symbol.complete(Symbol.java:633)
      at jdk.compiler/com.sun.tools.javac.code.Symbol$ClassSymbol.complete(Symbol.java:1314)
      at jdk.compiler/com.sun.tools.javac.code.Symbol$ClassSymbol.flags(Symbol.java:1248)
      at jdk.compiler/com.sun.tools.javac.code.Symbol$TypeSymbol.getEnclosedElements(Symbol.java:800)
      at jdk.javadoc/jdk.javadoc.internal.doclets.toolkit.util.Utils.getItems0(Utils.java:2468)
      at jdk.javadoc/jdk.javadoc.internal.doclets.toolkit.util.Utils.getItems0(Utils.java:2463)
      at jdk.javadoc/jdk.javadoc.internal.doclets.toolkit.util.Utils.recursiveGetItems(Utils.java:2451)
      at jdk.javadoc/jdk.javadoc.internal.doclets.toolkit.util.Utils$16.visitPackage(Utils.java:2436)
      at jdk.javadoc/jdk.javadoc.internal.doclets.toolkit.util.Utils$16.visitPackage(Utils.java:2432)
      at jdk.compiler/com.sun.tools.javac.code.Symbol$PackageSymbol.accept(Symbol.java:1166)
      at java.compiler@9-Ubuntu/javax.lang.model.util.AbstractElementVisitor6.visit(AbstractElementVisitor6.java:106)
      at jdk.javadoc/jdk.javadoc.internal.doclets.toolkit.util.Utils.getItems(Utils.java:2445)
      at jdk.javadoc/jdk.javadoc.internal.doclets.toolkit.util.Utils.getClasses(Utils.java:2182)
      at jdk.javadoc/jdk.javadoc.internal.doclets.toolkit.util.Utils.getAllClasses(Utils.java:2355)
      at jdk.javadoc/jdk.javadoc.internal.doclets.toolkit.builders.ConstantsSummaryBuilder.hasConstantField(ConstantsSummaryBuilder.java:258)
      at jdk.javadoc/jdk.javadoc.internal.doclets.toolkit.builders.ConstantsSummaryBuilder.buildContents(ConstantsSummaryBuilder.java:171)
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.base/java.lang.reflect.Method.invoke(Method.java:564)
      at jdk.javadoc/jdk.javadoc.internal.doclets.toolkit.builders.AbstractBuilder.build(AbstractBuilder.java:157)
      at jdk.javadoc/jdk.javadoc.internal.doclets.toolkit.builders.AbstractBuilder.buildChildren(AbstractBuilder.java:200)
      at jdk.javadoc/jdk.javadoc.internal.doclets.toolkit.builders.ConstantsSummaryBuilder.buildConstantSummary(ConstantsSummaryBuilder.java:156)
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.base/java.lang.reflect.Method.invoke(Method.java:564)
      at jdk.javadoc/jdk.javadoc.internal.doclets.toolkit.builders.AbstractBuilder.build(AbstractBuilder.java:157)
      at jdk.javadoc/jdk.javadoc.internal.doclets.toolkit.builders.ConstantsSummaryBuilder.build(ConstantsSummaryBuilder.java:136)
      at jdk.javadoc/jdk.javadoc.internal.doclets.toolkit.AbstractDoclet.generateOtherFiles(AbstractDoclet.java:228)
      at jdk.javadoc/jdk.javadoc.internal.doclets.formats.html.HtmlDoclet.generateOtherFiles(HtmlDoclet.java:116)
      at jdk.javadoc/jdk.javadoc.internal.doclets.toolkit.AbstractDoclet.startGeneration(AbstractDoclet.java:213)
      at jdk.javadoc/jdk.javadoc.internal.doclets.toolkit.AbstractDoclet.run(AbstractDoclet.java:117)
      at jdk.javadoc/jdk.javadoc.doclet.StandardDoclet.run(StandardDoclet.java:72)
      at jdk.javadoc/jdk.javadoc.internal.tool.Start.parseAndExecute(Start.java:574)
      at jdk.javadoc/jdk.javadoc.internal.tool.Start.begin(Start.java:423)
      at jdk.javadoc/jdk.javadoc.internal.tool.Start.begin(Start.java:340)
      at jdk.javadoc/jdk.javadoc.internal.tool.Main.execute(Main.java:63)
      at jdk.javadoc/jdk.javadoc.internal.tool.Main.main(Main.java:52)
      1 error


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      See "steps to reproduce".
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Teach the build system to remove the example classes from the source tree before building?

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: