Skip to content

Commit 2c7e47e

Browse files
8268774: Residual logging output written to STDOUT, not STDERR
Reviewed-by: prappo, hannesw
1 parent 8ea0606 commit 2c7e47e

5 files changed

Lines changed: 133 additions & 10 deletions

File tree

src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/Start.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,8 @@ private Result parseAndExecute(List<String> argList, Iterable<? extends JavaFile
560560
// We're done.
561561
if (options.verbose()) {
562562
long elapsedMillis = (System.nanoTime() - startNanos) / 1_000_000;
563-
log.noticeUsingKey("main.done_in", Long.toString(elapsedMillis));
563+
JavadocLog.printRawLines(log.getDiagnosticWriter(),
564+
log.getText("main.done_in", Long.toString(elapsedMillis)));
564565
}
565566

566567
return returnStatus;

src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/ToolEnvironment.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ public void notice(String key) {
199199
if (quiet) {
200200
return;
201201
}
202-
log.noticeUsingKey(key);
202+
JavadocLog.printRawLines(log.getDiagnosticWriter(), log.getText(key));
203203
}
204204

205205
/**
@@ -212,7 +212,7 @@ public void notice(String key, String a1) {
212212
if (quiet) {
213213
return;
214214
}
215-
log.noticeUsingKey(key, a1);
215+
JavadocLog.printRawLines(log.getDiagnosticWriter(), log.getText(key, a1));
216216
}
217217

218218
TreePath getTreePath(JCCompilationUnit tree) {

test/langtools/jdk/javadoc/tool/ToolProviderTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -123,7 +123,7 @@ public void testTwoStreamsErr() throws Exception {
123123
String out = swOut.toString();
124124
String err = swErr.toString();
125125

126-
if (!out.contains("Loading")) {
126+
if (!err.contains("Loading")) {
127127
error("stdout: unexpected output");
128128
}
129129
if (!err.contains("illegal character")) {

test/langtools/jdk/javadoc/tool/testLocaleOption/TestLocaleOption.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -155,22 +155,22 @@ public void testHelloWorldLocale(Path base) throws Exception {
155155

156156
private void testHelloWorld(Path base, Locale defaultLocale, Locale localeOption) throws Exception {
157157
Path apiDir = base.resolve("api");
158-
String stdOut = javadoc(defaultLocale,
158+
String stdErr = javadoc(defaultLocale,
159159
localeOption,
160160
"-sourcepath", srcDir.toString(),
161161
"-d", apiDir.toString(),
162162
"p")
163163
.writeAll()
164-
.getOutput(Task.OutputKind.STDOUT);
164+
.getOutput(Task.OutputKind.STDERR);
165165

166166
// check console messages
167167
if (Objects.equals(defaultLocale, ALLCAPS)) {
168-
checkContains(stdOut,
168+
checkContains(stdErr,
169169
"""
170170
LOADING SOURCE FILES FOR PACKAGE p...
171171
CONSTRUCTING JAVADOC INFORMATION...""");
172172
} else {
173-
checkContains(stdOut,
173+
checkContains(stdErr,
174174
"""
175175
Loading source files for package p...
176176
Constructing Javadoc information...""");
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/*
2+
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/*
25+
* @test
26+
* @bug 8268774
27+
* @summary Residual logging output written to STDOUT, not STDERR
28+
* @library /tools/lib ../../lib
29+
* @modules jdk.javadoc/jdk.javadoc.internal.tool
30+
* @build toolbox.ToolBox javadoc.tester.*
31+
* @run main TestToolStreams
32+
*/
33+
34+
import java.io.IOException;
35+
import java.nio.file.Path;
36+
37+
import javadoc.tester.JavadocTester;
38+
import toolbox.ToolBox;
39+
40+
// See also TestReporterStreams for testing doclet/reporter use of streams
41+
public class TestToolStreams extends JavadocTester {
42+
43+
public static void main(String... args) throws Exception {
44+
TestToolStreams tester = new TestToolStreams();
45+
tester.runTests(m -> new Object[]{Path.of(m.getName())});
46+
}
47+
48+
ToolBox tb = new ToolBox();
49+
50+
TestToolStreams() throws IOException {
51+
tb.writeJavaFiles(Path.of("src"),
52+
"""
53+
package p1;
54+
/** Comment 1. */
55+
public class C1 { }""",
56+
"""
57+
package p2;
58+
/** Comment 2. */
59+
public class C2 { }""");
60+
}
61+
62+
/**
63+
* Tests the entry point used by the DocumentationTool API and JavadocTester, in which
64+
* all output is written to a single specified writer.
65+
*/
66+
@Test
67+
public void testSingleStream(Path base) {
68+
test(base, false, Output.OUT, Output.OUT);
69+
}
70+
71+
/**
72+
* Tests the entry point used by the launcher, in which output is written to
73+
* writers that wrap {@code System.out} and {@code System.err}.
74+
*/
75+
@Test
76+
public void testStandardStreams(Path base) {
77+
test(base, true, Output.STDOUT, Output.STDERR);
78+
}
79+
80+
void test(Path base, boolean useStdStreams, Output stdOut, Output stdErr) {
81+
setOutputDirectoryCheck(DirectoryCheck.NONE);
82+
setUseStandardStreams(useStdStreams);
83+
84+
javadoc("--help");
85+
checkExit(Exit.OK);
86+
87+
if (stdOut != stdErr) {
88+
checkIsEmpty(stdErr);
89+
}
90+
91+
checkOutput(stdOut, true,
92+
"Usage:");
93+
94+
javadoc("-d", base.resolve("out").toString(),
95+
"-sourcepath", "src",
96+
"-verbose", // Note: triggers lots of javac messages as well as the javadoc time-taken message
97+
"p1",
98+
Path.of("src").resolve("p2").resolve("C2.java").toString());
99+
checkExit(Exit.OK);
100+
101+
if (stdOut != stdErr) {
102+
checkIsEmpty(stdOut);
103+
}
104+
105+
checkOutput(stdErr, true,
106+
"Loading source file src/p2/C2.java...".replace("/", FS),
107+
"Loading source files for package p1...",
108+
"Constructing Javadoc information",
109+
"[done in ", " ms]"
110+
);
111+
}
112+
113+
void checkIsEmpty(Output out) {
114+
checking("no output to " + out);
115+
String s = getOutput(out);
116+
if (s.isEmpty()) {
117+
passed("no output written to " + out);
118+
} else {
119+
failed(out + " is not empty");
120+
}
121+
}
122+
}

0 commit comments

Comments
 (0)