Skip to content

Commit 60a2072

Browse files
author
Alex Menkov
committed
8260431: com/sun/jdi/JdbOptions.java failed with "RuntimeException: 'prop[boo] = >foo<' missing from stdout/stderr"
Reviewed-by: sspitsyn, cjplummer
1 parent bf47a47 commit 60a2072

File tree

1 file changed

+50
-21
lines changed

1 file changed

+50
-21
lines changed

test/jdk/com/sun/jdi/JdbOptions.java

Lines changed: 50 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,17 @@
3434
import lib.jdb.JdbCommand;
3535
import jdk.test.lib.process.OutputAnalyzer;
3636

37+
import java.io.IOException;
38+
import java.io.PrintStream;
3739
import java.lang.management.ManagementFactory;
40+
import java.nio.charset.StandardCharsets;
41+
import java.nio.file.Files;
42+
import java.nio.file.Path;
43+
import java.nio.file.Paths;
3844
import java.util.Arrays;
3945
import java.util.List;
46+
import java.util.UUID;
47+
import java.util.stream.Collectors;
4048

4149
class JbdOptionsTarg {
4250
static final String OK_MSG = "JbdOptionsTarg: OK";
@@ -49,47 +57,62 @@ static String propString(String name, String value) {
4957
return "prop[" + name + "] = >" + value + "<";
5058
}
5159

52-
public static void main(String[] args) {
53-
System.out.println(OK_MSG);
54-
// print all args
55-
List<String> vmArgs = ManagementFactory.getRuntimeMXBean().getInputArguments();
56-
for (String s: vmArgs) {
57-
System.out.println(argString(s));
58-
}
59-
// print requested sys.props
60-
for (String p: args) {
61-
System.out.println(propString(p, System.getProperty(p)));
60+
/**
61+
* 1st argument is a filename to redirect application output,
62+
* the rest are names of the properties to dump.
63+
*/
64+
public static void main(String[] args) throws IOException {
65+
String outFile = args[0];
66+
try (PrintStream out = new PrintStream(outFile, StandardCharsets.UTF_8)) {
67+
out.println(OK_MSG);
68+
// print all args
69+
List<String> vmArgs = ManagementFactory.getRuntimeMXBean().getInputArguments();
70+
for (String s : vmArgs) {
71+
out.println(argString(s));
72+
}
73+
// print requested sys.props (skip 1st arg which is output filename)
74+
for (int i=1; i < args.length; i++) {
75+
String p = args[i];
76+
out.println(propString(p, System.getProperty(p)));
77+
}
6278
}
6379
}
6480
}
6581

6682
public class JdbOptions {
83+
private static final String outFilename = UUID.randomUUID().toString() + ".out";
84+
private static final Path outPath = Paths.get(outFilename);
6785
private static final String targ = JbdOptionsTarg.class.getName();
6886

6987
public static void main(String[] args) throws Exception {
7088
// the simplest case
7189
test("-connect",
72-
"com.sun.jdi.CommandLineLaunch:vmexec=java,options=-client -XX:+PrintVMOptions,main=" + targ)
90+
"com.sun.jdi.CommandLineLaunch:vmexec=java,options=-client -XX:+PrintVMOptions"
91+
+ ",main=" + targ + " " + outFilename)
7392
.expectedArg("-XX:+PrintVMOptions");
7493

7594
// pass property through 'options'
7695
test("-connect",
77-
"com.sun.jdi.CommandLineLaunch:vmexec=java,options='-Dboo=foo',main=" + targ + " boo")
96+
"com.sun.jdi.CommandLineLaunch:vmexec=java,options='-Dboo=foo'"
97+
+ ",main=" + targ + " " + outFilename + " boo")
7898
.expectedProp("boo", "foo");
7999

80100
// property with spaces
81101
test("-connect",
82-
"com.sun.jdi.CommandLineLaunch:vmexec=java,options=\"-Dboo=foo 2\",main=" + targ + " boo")
102+
"com.sun.jdi.CommandLineLaunch:vmexec=java,options=\"-Dboo=foo 2\""
103+
+ ",main=" + targ + " " + outFilename + " boo")
83104
.expectedProp("boo", "foo 2");
84105

85106
// property with spaces (with single quotes)
86107
test("-connect",
87-
"com.sun.jdi.CommandLineLaunch:vmexec=java,options='-Dboo=foo 2',main=" + targ + " boo")
108+
"com.sun.jdi.CommandLineLaunch:vmexec=java,options='-Dboo=foo 2'"
109+
+ ",main=" + targ + " " + outFilename + " boo")
88110
.expectedProp("boo", "foo 2");
89111

90112
// properties with spaces (with single quotes)
91113
test("-connect",
92-
"com.sun.jdi.CommandLineLaunch:vmexec=java,options=-Dboo=foo '-Dboo2=foo 2',main=" + targ + " boo boo2")
114+
"com.sun.jdi.CommandLineLaunch:vmexec=java,options=-Dboo=foo '-Dboo2=foo 2'"
115+
+ ",main=" + targ + " " + outFilename + " boo boo2")
93116
.expectedProp("boo", "foo")
94117
.expectedProp("boo2", "foo 2");
95118

@@ -98,7 +121,7 @@ public static void main(String[] args) throws Exception {
98121
"com.sun.jdi.CommandLineLaunch:vmexec=java,options=\"-client\" \"-XX:+PrintVMOptions\""
99122
+ " -XX:+IgnoreUnrecognizedVMOptions"
100123
+ " \"-XX:StartFlightRecording=dumponexit=true,maxsize=500M\" \"-XX:FlightRecorderOptions=repository=jfrrep\""
101-
+ ",main=" + targ)
124+
+ ",main=" + targ + " " + outFilename)
102125
.expectedArg("-XX:StartFlightRecording=dumponexit=true,maxsize=500M")
103126
.expectedArg("-XX:FlightRecorderOptions=repository=jfrrep");
104127

@@ -107,7 +130,7 @@ public static void main(String[] args) throws Exception {
107130
"com.sun.jdi.CommandLineLaunch:vmexec=java,options='-client' '-XX:+PrintVMOptions'"
108131
+ " -XX:+IgnoreUnrecognizedVMOptions"
109132
+ " '-XX:StartFlightRecording=dumponexit=true,maxsize=500M' '-XX:FlightRecorderOptions=repository=jfrrep'"
110-
+ ",main=" + targ)
133+
+ ",main=" + targ + " " + outFilename)
111134
.expectedArg("-XX:StartFlightRecording=dumponexit=true,maxsize=500M")
112135
.expectedArg("-XX:FlightRecorderOptions=repository=jfrrep");
113136

@@ -120,7 +143,7 @@ public static void main(String[] args) throws Exception {
120143
+ " -XX:+IgnoreUnrecognizedVMOptions"
121144
+ " \"-XX:StartFlightRecording=dumponexit=true,maxsize=500M\""
122145
+ " '-XX:FlightRecorderOptions=repository=jfrrep'"
123-
+ ",main=" + targ + " prop1 prop2 prop3 prop4")
146+
+ ",main=" + targ + " " + outFilename + " prop1 prop2 prop3 prop4")
124147
.expectedProp("prop1", "val1")
125148
.expectedProp("prop2", "val 2")
126149
.expectedProp("prop3", "val3")
@@ -154,12 +177,18 @@ private static TestResult test(String... args) throws Exception {
154177
.map(s -> s.replace("\"", "\\\""))
155178
.toArray(String[]::new);
156179
}
180+
157181
try (Jdb jdb = new Jdb(args)) {
158182
jdb.waitForSimplePrompt(1024, true); // 1024 lines should be enough
159183
jdb.command(JdbCommand.run().allowExit());
160-
OutputAnalyzer out = new OutputAnalyzer(jdb.getJdbOutput());
161-
out.shouldContain(JbdOptionsTarg.OK_MSG);
162-
return new TestResult(out);
163184
}
185+
String output = Files.readAllLines(outPath, StandardCharsets.UTF_8).stream()
186+
.collect(Collectors.joining(System.getProperty("line.separator")));
187+
Files.deleteIfExists(outPath);
188+
System.out.println("Debuggee output: [");
189+
System.out.println(output);
190+
System.out.println("]");
191+
OutputAnalyzer out = new OutputAnalyzer(output);
192+
return new TestResult(out);
164193
}
165194
}

0 commit comments

Comments
 (0)