6964914: javadoc does not output number of warnings using user written doclet

Fri, 04 Mar 2011 19:59:04 -0800

author
jjg
date
Fri, 04 Mar 2011 19:59:04 -0800
changeset 912
5e6c661891da
parent 911
4ee7de0684f5
child 913
74f0c05c51eb

6964914: javadoc does not output number of warnings using user written doclet
Reviewed-by: bpatel

src/share/classes/com/sun/tools/javadoc/DocletInvoker.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javadoc/Messager.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javadoc/RootDocImpl.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javadoc/Start.java file | annotate | diff | comparison | revisions
test/tools/javadoc/6964914/Error.java file | annotate | diff | comparison | revisions
test/tools/javadoc/6964914/JavacWarning.java file | annotate | diff | comparison | revisions
test/tools/javadoc/6964914/JavadocWarning.java file | annotate | diff | comparison | revisions
test/tools/javadoc/6964914/Test.java file | annotate | diff | comparison | revisions
test/tools/javadoc/6964914/TestStdDoclet.java file | annotate | diff | comparison | revisions
test/tools/javadoc/6964914/TestUserDoclet.java file | annotate | diff | comparison | revisions
test/tools/javadoc/T6968833.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javadoc/DocletInvoker.java	Fri Mar 04 19:56:02 2011 -0800
     1.2 +++ b/src/share/classes/com/sun/tools/javadoc/DocletInvoker.java	Fri Mar 04 19:59:04 2011 -0800
     1.3 @@ -1,5 +1,5 @@
     1.4  /*
     1.5 - * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
     1.6 + * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
     1.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.8   *
     1.9   * This code is free software; you can redistribute it and/or modify it
    1.10 @@ -31,14 +31,13 @@
    1.11  
    1.12  import com.sun.tools.javac.util.List;
    1.13  
    1.14 -import java.net.*;
    1.15 +import java.io.File;
    1.16  import java.lang.reflect.Method;
    1.17  import java.lang.reflect.Modifier;
    1.18  import java.lang.reflect.InvocationTargetException;
    1.19 +import java.net.URL;
    1.20 +import java.net.URLClassLoader;
    1.21  
    1.22 -import java.io.File;
    1.23 -import java.io.IOException;
    1.24 -import java.util.StringTokenizer;
    1.25  
    1.26  /**
    1.27   * Class creates, controls and invokes doclets.
     2.1 --- a/src/share/classes/com/sun/tools/javadoc/Messager.java	Fri Mar 04 19:56:02 2011 -0800
     2.2 +++ b/src/share/classes/com/sun/tools/javadoc/Messager.java	Fri Mar 04 19:59:04 2011 -0800
     2.3 @@ -143,11 +143,9 @@
     2.4       * if needed.
     2.5       */
     2.6      private String getString(String key) {
     2.7 -        ResourceBundle messageRB = this.messageRB;
     2.8          if (messageRB == null) {
     2.9              try {
    2.10 -                this.messageRB = messageRB =
    2.11 -                    ResourceBundle.getBundle(
    2.12 +                messageRB = ResourceBundle.getBundle(
    2.13                            "com.sun.tools.javadoc.resources.javadoc");
    2.14              } catch (MissingResourceException e) {
    2.15                  throw new Error("Fatal: Resource for javadoc is missing");
    2.16 @@ -456,8 +454,6 @@
    2.17       * Print exit message.
    2.18       */
    2.19      public void exitNotice() {
    2.20 -        int nerrors = nerrors();
    2.21 -        int nwarnings = nwarnings();
    2.22          if (nerrors > 0) {
    2.23              notice((nerrors > 1) ? "main.errors" : "main.error",
    2.24                     "" + nerrors);
     3.1 --- a/src/share/classes/com/sun/tools/javadoc/RootDocImpl.java	Fri Mar 04 19:56:02 2011 -0800
     3.2 +++ b/src/share/classes/com/sun/tools/javadoc/RootDocImpl.java	Fri Mar 04 19:59:04 2011 -0800
     3.3 @@ -1,5 +1,5 @@
     3.4  /*
     3.5 - * Copyright (c) 1997, 2009, Oracle and/or its affiliates. All rights reserved.
     3.6 + * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
     3.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3.8   *
     3.9   * This code is free software; you can redistribute it and/or modify it
    3.10 @@ -322,6 +322,7 @@
    3.11      /**
    3.12       * Do lazy initialization of "documentation" string.
    3.13       */
    3.14 +    @Override
    3.15      protected String documentation() {
    3.16          if (documentation == null) {
    3.17              int cnt = options.length();
    3.18 @@ -348,6 +349,7 @@
    3.19       * Return the source position of the entity, or null if
    3.20       * no position is available.
    3.21       */
    3.22 +    @Override
    3.23      public SourcePosition position() {
    3.24          JavaFileObject path;
    3.25          return ((path = getOverviewPath()) == null) ?
     4.1 --- a/src/share/classes/com/sun/tools/javadoc/Start.java	Fri Mar 04 19:56:02 2011 -0800
     4.2 +++ b/src/share/classes/com/sun/tools/javadoc/Start.java	Fri Mar 04 19:59:04 2011 -0800
     4.3 @@ -1,5 +1,5 @@
     4.4  /*
     4.5 - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
     4.6 + * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
     4.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4.8   *
     4.9   * This code is free software; you can redistribute it and/or modify it
    4.10 @@ -396,6 +396,10 @@
    4.11          boolean ok = root != null;
    4.12          if (ok) ok = docletInvoker.start(root);
    4.13  
    4.14 +        Messager docletMessager = Messager.instance0(context);
    4.15 +        messager.nwarnings += docletMessager.nwarnings;
    4.16 +        messager.nerrors += docletMessager.nerrors;
    4.17 +
    4.18          // We're done.
    4.19          if (compOpts.get("-verbose") != null) {
    4.20              tm = System.currentTimeMillis() - tm;
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/test/tools/javadoc/6964914/Error.java	Fri Mar 04 19:59:04 2011 -0800
     5.3 @@ -0,0 +1,26 @@
     5.4 +/*
     5.5 + * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
     5.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     5.7 + *
     5.8 + * This code is free software; you can redistribute it and/or modify it
     5.9 + * under the terms of the GNU General Public License version 2 only, as
    5.10 + * published by the Free Software Foundation.
    5.11 + *
    5.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    5.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    5.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    5.15 + * version 2 for more details (a copy is included in the LICENSE file that
    5.16 + * accompanied this code).
    5.17 + *
    5.18 + * You should have received a copy of the GNU General Public License version
    5.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    5.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    5.21 + *
    5.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    5.23 + * or visit www.oracle.com if you need additional information or have any
    5.24 + * questions.
    5.25 + */
    5.26 +
    5.27 +public class Error {
    5.28 +    Object x // no semicolon
    5.29 +}
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/test/tools/javadoc/6964914/JavacWarning.java	Fri Mar 04 19:59:04 2011 -0800
     6.3 @@ -0,0 +1,26 @@
     6.4 +/*
     6.5 + * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
     6.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     6.7 + *
     6.8 + * This code is free software; you can redistribute it and/or modify it
     6.9 + * under the terms of the GNU General Public License version 2 only, as
    6.10 + * published by the Free Software Foundation.
    6.11 + *
    6.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    6.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    6.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    6.15 + * version 2 for more details (a copy is included in the LICENSE file that
    6.16 + * accompanied this code).
    6.17 + *
    6.18 + * You should have received a copy of the GNU General Public License version
    6.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    6.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    6.21 + *
    6.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    6.23 + * or visit www.oracle.com if you need additional information or have any
    6.24 + * questions.
    6.25 + */
    6.26 +
    6.27 +public class JavacWarning {
    6.28 +    int enum;  // warning in source 1.4
    6.29 +}
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/test/tools/javadoc/6964914/JavadocWarning.java	Fri Mar 04 19:59:04 2011 -0800
     7.3 @@ -0,0 +1,27 @@
     7.4 +/*
     7.5 + * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
     7.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     7.7 + *
     7.8 + * This code is free software; you can redistribute it and/or modify it
     7.9 + * under the terms of the GNU General Public License version 2 only, as
    7.10 + * published by the Free Software Foundation.
    7.11 + *
    7.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    7.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    7.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    7.15 + * version 2 for more details (a copy is included in the LICENSE file that
    7.16 + * accompanied this code).
    7.17 + *
    7.18 + * You should have received a copy of the GNU General Public License version
    7.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    7.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    7.21 + *
    7.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    7.23 + * or visit www.oracle.com if you need additional information or have any
    7.24 + * questions.
    7.25 + */
    7.26 +
    7.27 +public class JavadocWarning {
    7.28 +    /** @see DoesNotExist */
    7.29 +    int x;
    7.30 +}
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/test/tools/javadoc/6964914/Test.java	Fri Mar 04 19:59:04 2011 -0800
     8.3 @@ -0,0 +1,78 @@
     8.4 +/*
     8.5 + * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
     8.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     8.7 + *
     8.8 + * This code is free software; you can redistribute it and/or modify it
     8.9 + * under the terms of the GNU General Public License version 2 only, as
    8.10 + * published by the Free Software Foundation.
    8.11 + *
    8.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    8.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    8.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    8.15 + * version 2 for more details (a copy is included in the LICENSE file that
    8.16 + * accompanied this code).
    8.17 + *
    8.18 + * You should have received a copy of the GNU General Public License version
    8.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    8.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    8.21 + *
    8.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    8.23 + * or visit www.oracle.com if you need additional information or have any
    8.24 + * questions.
    8.25 + */
    8.26 +
    8.27 +/*
    8.28 + * @test
    8.29 + * @bug 6964914
    8.30 + * @summary javadoc does not output number of warnings using user written doclet
    8.31 + */
    8.32 +
    8.33 +import java.io.*;
    8.34 +
    8.35 +public class Test {
    8.36 +    public static void main(String... args) throws Exception {
    8.37 +        new Test().run();
    8.38 +    }
    8.39 +
    8.40 +    public void run() throws Exception {
    8.41 +        javadoc("Error.java", "1 error");
    8.42 +        javadoc("JavacWarning.java", "1 warning");
    8.43 +        javadoc("JavadocWarning.java", "1 warning");
    8.44 +        if (errors > 0)
    8.45 +            throw new Exception(errors + " errors found");
    8.46 +    }
    8.47 +
    8.48 +    void javadoc(String path, String expect) {
    8.49 +        File testSrc = new File(System.getProperty("test.src"));
    8.50 +        String[] args = {
    8.51 +            "-source", "1.4", // enables certain Parser warnings
    8.52 +            "-bootclasspath", System.getProperty("sun.boot.class.path"),
    8.53 +            "-classpath", ".",
    8.54 +            "-package",
    8.55 +            new File(testSrc, path).getPath()
    8.56 +        };
    8.57 +
    8.58 +        StringWriter sw = new StringWriter();
    8.59 +        PrintWriter pw = new PrintWriter(sw);
    8.60 +        int rc = com.sun.tools.javadoc.Main.execute(
    8.61 +                "javadoc",
    8.62 +                pw, pw, pw,
    8.63 +                com.sun.tools.doclets.standard.Standard.class.getName(),
    8.64 +                args);
    8.65 +        pw.close();
    8.66 +        String out = sw.toString();
    8.67 +        if (!out.isEmpty())
    8.68 +            System.err.println(out);
    8.69 +        System.err.println("javadoc exit: rc=" + rc);
    8.70 +
    8.71 +        if (!out.contains(expect))
    8.72 +            error("expected text not found: " + expect);
    8.73 +    }
    8.74 +
    8.75 +    void error(String msg) {
    8.76 +        System.err.println("Error: " + msg);
    8.77 +        errors++;
    8.78 +    }
    8.79 +
    8.80 +    int errors;
    8.81 +}
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/test/tools/javadoc/6964914/TestStdDoclet.java	Fri Mar 04 19:59:04 2011 -0800
     9.3 @@ -0,0 +1,100 @@
     9.4 +/*
     9.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
     9.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     9.7 + *
     9.8 + * This code is free software; you can redistribute it and/or modify it
     9.9 + * under the terms of the GNU General Public License version 2 only, as
    9.10 + * published by the Free Software Foundation.
    9.11 + *
    9.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    9.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    9.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    9.15 + * version 2 for more details (a copy is included in the LICENSE file that
    9.16 + * accompanied this code).
    9.17 + *
    9.18 + * You should have received a copy of the GNU General Public License version
    9.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    9.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    9.21 + *
    9.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    9.23 + * or visit www.oracle.com if you need additional information or have any
    9.24 + * questions.
    9.25 + */
    9.26 +
    9.27 +/*
    9.28 + * @test
    9.29 + * @bug 6964914
    9.30 + * @summary javadoc does not output number of warnings using user written doclet
    9.31 + */
    9.32 +
    9.33 +import java.io.*;
    9.34 +
    9.35 +/**
    9.36 + * Dummy javadoc comment.
    9.37 + * @author jjg
    9.38 + * @see DoesNotExist
    9.39 + */
    9.40 +public class TestStdDoclet {
    9.41 +    public static void main(String... args) throws Exception {
    9.42 +        new TestStdDoclet().run();
    9.43 +    }
    9.44 +
    9.45 +    /**
    9.46 +     * More dummy comments.
    9.47 +     * @throws DoesNotExist   oops, javadoc does not see this
    9.48 +     * @see DoesNotExist
    9.49 +     */
    9.50 +    void run() throws Exception {
    9.51 +        File javaHome = new File(System.getProperty("java.home"));
    9.52 +        if (javaHome.getName().equals("jre"))
    9.53 +            javaHome = javaHome.getParentFile();
    9.54 +        File javadoc = new File(new File(javaHome, "bin"), "javadoc");
    9.55 +        File testSrc = new File(System.getProperty("test.src"));
    9.56 +
    9.57 +        // run javadoc in separate process to ensure doclet executed under
    9.58 +        // normal user conditions w.r.t. classloader
    9.59 +        String thisClassName = TestStdDoclet.class.getName();
    9.60 +        Process p = new ProcessBuilder()
    9.61 +            .command(javadoc.getPath(),
    9.62 +                "-J-Xbootclasspath:" + System.getProperty("sun.boot.class.path"),
    9.63 +                "-package",
    9.64 +                new File(testSrc, thisClassName + ".java").getPath())
    9.65 +            .redirectErrorStream(true)
    9.66 +            .start();
    9.67 +
    9.68 +        int actualDocletWarnCount = 0;
    9.69 +        int reportedDocletWarnCount = 0;
    9.70 +        BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
    9.71 +        try {
    9.72 +            String line;
    9.73 +            while ((line = in.readLine()) != null) {
    9.74 +                System.err.println(line);
    9.75 +                if (line.contains("DoesNotExist"))
    9.76 +                    actualDocletWarnCount++;
    9.77 +                if (line.matches("[0-9]+ warning(s)?"))
    9.78 +                    reportedDocletWarnCount =
    9.79 +                            Integer.valueOf(line.substring(0, line.indexOf(" ")));
    9.80 +            }
    9.81 +        } finally {
    9.82 +            in.close();
    9.83 +        }
    9.84 +        int rc = p.waitFor();
    9.85 +        if (rc != 0)
    9.86 +            System.err.println("javadoc failed, rc:" + rc);
    9.87 +
    9.88 +        int expectedDocletWarnCount = 2;
    9.89 +        checkEqual("actual", actualDocletWarnCount, "expected", expectedDocletWarnCount);
    9.90 +        checkEqual("actual", actualDocletWarnCount, "reported", reportedDocletWarnCount);
    9.91 +    }
    9.92 +
    9.93 +    /**
    9.94 +     * Private method should not cause a warning.
    9.95 +     * @see DoesNotExist
    9.96 +     */
    9.97 +    private void checkEqual(String l1, int i1, String l2, int i2) throws Exception {
    9.98 +        if (i1 != i2)
    9.99 +            throw new Exception(l1 + " warn count, " + i1 + ", does not match "
   9.100 +                        + l2 + " warn count, " + i2);
   9.101 +    }
   9.102 +
   9.103 +}
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/test/tools/javadoc/6964914/TestUserDoclet.java	Fri Mar 04 19:59:04 2011 -0800
    10.3 @@ -0,0 +1,99 @@
    10.4 +/*
    10.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
    10.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    10.7 + *
    10.8 + * This code is free software; you can redistribute it and/or modify it
    10.9 + * under the terms of the GNU General Public License version 2 only, as
   10.10 + * published by the Free Software Foundation.
   10.11 + *
   10.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   10.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   10.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   10.15 + * version 2 for more details (a copy is included in the LICENSE file that
   10.16 + * accompanied this code).
   10.17 + *
   10.18 + * You should have received a copy of the GNU General Public License version
   10.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   10.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   10.21 + *
   10.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   10.23 + * or visit www.oracle.com if you need additional information or have any
   10.24 + * questions.
   10.25 + */
   10.26 +
   10.27 +/*
   10.28 + * @test
   10.29 + * @bug 6964914
   10.30 + * @summary javadoc does not output number of warnings using user written doclet
   10.31 + */
   10.32 +
   10.33 +import java.io.*;
   10.34 +import com.sun.javadoc.Doclet;
   10.35 +import com.sun.javadoc.RootDoc;
   10.36 +
   10.37 +public class TestUserDoclet extends Doclet {
   10.38 +    public static void main(String... args) throws Exception {
   10.39 +        new TestUserDoclet().run();
   10.40 +    }
   10.41 +
   10.42 +    static final String docletWarning = "warning from test doclet";
   10.43 +
   10.44 +    /** Main doclet method. */
   10.45 +    public static boolean start(RootDoc root) {
   10.46 +        root.printWarning(null, docletWarning);
   10.47 +        return true;
   10.48 +    }
   10.49 +
   10.50 +    /** Main test method. */
   10.51 +    void run() throws Exception {
   10.52 +        File javaHome = new File(System.getProperty("java.home"));
   10.53 +        if (javaHome.getName().equals("jre"))
   10.54 +            javaHome = javaHome.getParentFile();
   10.55 +        File javadoc = new File(new File(javaHome, "bin"), "javadoc");
   10.56 +        File testSrc = new File(System.getProperty("test.src"));
   10.57 +        File testClasses = new File(System.getProperty("test.classes"));
   10.58 +
   10.59 +        // run javadoc in separate process to ensure doclet executed under
   10.60 +        // normal user conditions w.r.t. classloader
   10.61 +        String thisClassName = TestUserDoclet.class.getName();
   10.62 +        Process p = new ProcessBuilder()
   10.63 +            .command(javadoc.getPath(),
   10.64 +                "-J-Xbootclasspath:" + System.getProperty("sun.boot.class.path"),
   10.65 +                "-doclet", thisClassName,
   10.66 +                "-docletpath", testClasses.getPath(),
   10.67 +                new File(testSrc, thisClassName + ".java").getPath())
   10.68 +            .redirectErrorStream(true)
   10.69 +            .start();
   10.70 +
   10.71 +        int actualDocletWarnCount = 0;
   10.72 +        int reportedDocletWarnCount = 0;
   10.73 +        BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
   10.74 +        try {
   10.75 +            String line;
   10.76 +            while ((line = in.readLine()) != null) {
   10.77 +                System.err.println(line);
   10.78 +                if (line.contains(docletWarning))
   10.79 +                    actualDocletWarnCount++;
   10.80 +                if (line.matches("[0-9]+ warning(s)?"))
   10.81 +                    reportedDocletWarnCount =
   10.82 +                            Integer.valueOf(line.substring(0, line.indexOf(" ")));
   10.83 +            }
   10.84 +        } finally {
   10.85 +            in.close();
   10.86 +        }
   10.87 +        int rc = p.waitFor();
   10.88 +        if (rc != 0)
   10.89 +            System.err.println("javadoc failed, rc:" + rc);
   10.90 +
   10.91 +        int expectedDocletWarnCount = 1;
   10.92 +        checkEqual("actual", actualDocletWarnCount, "expected", expectedDocletWarnCount);
   10.93 +        checkEqual("actual", actualDocletWarnCount, "reported", reportedDocletWarnCount);
   10.94 +    }
   10.95 +
   10.96 +    void checkEqual(String l1, int i1, String l2, int i2) throws Exception {
   10.97 +        if (i1 != i2)
   10.98 +            throw new Exception(l1 + " warn count, " + i1 + ", does not match "
   10.99 +                        + l2 + " warn count, " + i2);
  10.100 +    }
  10.101 +
  10.102 +}
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/test/tools/javadoc/T6968833.java	Fri Mar 04 19:59:04 2011 -0800
    11.3 @@ -0,0 +1,56 @@
    11.4 +/*
    11.5 + * Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
    11.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    11.7 + *
    11.8 + * This code is free software; you can redistribute it and/or modify it
    11.9 + * under the terms of the GNU General Public License version 2 only, as
   11.10 + * published by the Free Software Foundation.
   11.11 + *
   11.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   11.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   11.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   11.15 + * version 2 for more details (a copy is included in the LICENSE file that
   11.16 + * accompanied this code).
   11.17 + *
   11.18 + * You should have received a copy of the GNU General Public License version
   11.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   11.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   11.21 + *
   11.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   11.23 + * or visit www.oracle.com if you need additional information or have any
   11.24 + * questions.
   11.25 + */
   11.26 +
   11.27 +/*
   11.28 + * @test
   11.29 + * @bug 6968833
   11.30 + * @summary javadoc reports error but still returns 0
   11.31 + */
   11.32 +
   11.33 +import java.io.*;
   11.34 +
   11.35 +public class T6968833 {
   11.36 +    public static void main(String... args) throws IOException {
   11.37 +        new T6968833().run();
   11.38 +    }
   11.39 +
   11.40 +    void run() throws IOException {
   11.41 +        File srcDir = new File("src");
   11.42 +        // following file causes error: No public or protected classes found to document.
   11.43 +        File f = writeFile(srcDir, "Foo.java", "class Foo { }");
   11.44 +        String[] args = { f.getPath() };
   11.45 +        int rc = com.sun.tools.javadoc.Main.execute(args);
   11.46 +        if (rc == 0)
   11.47 +            throw new Error("Unexpected exit from javadoc: " + rc);
   11.48 +    }
   11.49 +
   11.50 +    File writeFile(File dir, String path, String s) throws IOException {
   11.51 +        File f = new File(dir, path);
   11.52 +        f.getParentFile().mkdirs();
   11.53 +        try (Writer out = new FileWriter(f)) {
   11.54 +            out.write(s);
   11.55 +        }
   11.56 +        return f;
   11.57 +    }
   11.58 +}
   11.59 +

mercurial