# HG changeset patch # User jjg # Date 1360020610 28800 # Node ID 2c686ad681f5300482ffc17f88bdc80e3bba2d47 # Parent 040a54631aad716beab91fe9418c2fd4b973be81 8007490: NPE from DocumentationTool.run Reviewed-by: darcy diff -r 040a54631aad -r 2c686ad681f5 langtools/src/share/classes/com/sun/tools/javadoc/api/JavadocTool.java --- a/langtools/src/share/classes/com/sun/tools/javadoc/api/JavadocTool.java Sun Feb 03 02:31:30 2013 +0000 +++ b/langtools/src/share/classes/com/sun/tools/javadoc/api/JavadocTool.java Mon Feb 04 15:30:10 2013 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2013, 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 @@ -139,8 +139,8 @@ @Override public int run(InputStream in, OutputStream out, OutputStream err, String... arguments) { - PrintWriter err_pw = new PrintWriter(err, true); - PrintWriter out_pw = new PrintWriter(out); + PrintWriter err_pw = new PrintWriter(err == null ? System.err : err, true); + PrintWriter out_pw = new PrintWriter(out == null ? System.out : out); try { String standardDocletName = "com.sun.tools.doclets.standard.Standard"; return com.sun.tools.javadoc.Main.execute( diff -r 040a54631aad -r 2c686ad681f5 langtools/test/tools/javadoc/api/basic/RunTest.java --- a/langtools/test/tools/javadoc/api/basic/RunTest.java Sun Feb 03 02:31:30 2013 +0000 +++ b/langtools/test/tools/javadoc/api/basic/RunTest.java Mon Feb 04 15:30:10 2013 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2013, 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 6493690 + * @bug 6493690 8007490 * @summary javadoc should have a javax.tools.Tool service provider * @build APITest * @run main RunTest @@ -31,6 +31,7 @@ import java.io.ByteArrayOutputStream; import java.io.File; +import java.io.PrintStream; import javax.tools.DocumentationTool; import javax.tools.ToolProvider; @@ -46,7 +47,7 @@ * Verify that run method can be invoked. */ @Test - public void testRun() throws Exception { + public void testRunOK() throws Exception { File testSrc = new File(System.getProperty("test.src")); File srcFile = new File(testSrc, "pkg/C.java"); File outDir = getOutDir(); @@ -77,7 +78,7 @@ * Verify that run method can be invoked. */ @Test - public void testRun2() throws Exception { + public void testRunFail() throws Exception { File outDir = getOutDir(); String badfile = "badfile.java"; String[] args = { "-d", outDir.getPath(), badfile }; @@ -100,5 +101,48 @@ } } + /** + * Verify that null args are accepted. + */ + @Test + public void testNullArgs() throws Exception { + File testSrc = new File(System.getProperty("test.src")); + File srcFile = new File(testSrc, "pkg/C.java"); + File outDir = getOutDir(); + String[] args = { "-d", outDir.getPath(), srcFile.getPath() }; + + ByteArrayOutputStream stdout = new ByteArrayOutputStream(); + PrintStream prevStdout = System.out; + System.setOut(new PrintStream(stdout)); + + ByteArrayOutputStream stderr = new ByteArrayOutputStream(); + PrintStream prevStderr = System.err; + System.setErr(new PrintStream(stderr)); + + int rc ; + try { + DocumentationTool tool = ToolProvider.getSystemDocumentationTool(); + rc = tool.run(null, null, null, args); + } finally { + System.setOut(prevStdout); + System.setErr(prevStderr); + } + + System.err.println("stdout >>" + stdout.toString() + "<<"); + System.err.println("stderr >>" + stderr.toString() + "<<"); + + if (rc == 0) { + System.err.println("call succeeded"); + checkFiles(outDir, standardExpectFiles); + String out = stdout.toString(); + for (String f: standardExpectFiles) { + String f1 = f.replace('/', File.separatorChar); + if (f1.endsWith(".html") && !out.contains(f1)) + error("expected string not found: " + f1); + } + } else { + error("call failed"); + } + } }