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

com.sun.tools.javadoc.Main.execute ignores PrintWriters

XMLWordPrintable

    • hopper
    • generic
    • generic



      Name: nt126004 Date: 12/10/2001


      java version "1.4.0-beta3"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta3-b84)
      Java HotSpot(TM) Client VM (build 1.4.0-beta3-b84, mixed mode)


      When using com.sun.tools.javadoc.Main.execute(
          java.lang.String programName,
          java.io.PrintWriter errWriter,
          java.io.PrintWriter warnWriter,
          java.io.PrintWriter noticeWriter,
          java.lang.String defaultDocletClassName,
          java.lang.String[] args)

      it seems that the errWriter,warnWriter and noticeWriter parameters are
      ignored.


      int result = Main.execute("myDocletClass",
          new java.io.PrintWriter(new java.io.ByteArrayOutputStream()),
          new java.io.PrintWriter(new java.io.ByteArrayOutputStream()),
          new java.io.PrintWriter(new java.io.ByteArrayOutputStream()),
          "myDocletClassName","MyJavaFile.java");

      should print:

      Loading source file MyJavaFile.java...
      Constructing Javadoc information...

      to stdout, right?

      The following programm shows the bug:

      import java.io.*;
      import com.sun.tools.javadoc.Main;

      public class Test {

      public static void main(String[] args) {

      ByteArrayOutputStream redirectedOutput = new
      ByteArrayOutputStream();
      PrintStream originalOutput = System.out;
      // redirect System.out to a buffer
      System.setOut(new PrintStream(redirectedOutput));

      // execute javadoc
      int result = Main.execute(
      "StandardDoclet",
      new PrintWriter(new ByteArrayOutputStream()),
      new PrintWriter(new ByteArrayOutputStream()),
      new PrintWriter(new ByteArrayOutputStream()),
      "com.sun.tools.doclets.standard.Standard",
      new String[] {"Test.java"}
      );

      // test whether javadoc did any output to System.out
      if (redirectedOutput.toByteArray().length > 0) {
      originalOutput.println("Bug still exists.");
      } else {
      originalOutput.println("Bug fixed.");
      }
      }
      }

        To run the Test just compile it with javac and run it. The classpath must
      contain the JAVA_HOME/lib/tools.jar file.
      (Review ID: 136921)
      ======================================================================

            gafter Neal Gafter (Inactive)
            nthompsosunw Nathanael Thompson (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: