Skip to content

Commit

Permalink
8259266: com/sun/jdi/JdbOptions.java failed with "RuntimeException: '…
Browse files Browse the repository at this point in the history
…prop[boo] = >foo 2<' missing from stdout/stderr"

8260431: com/sun/jdi/JdbOptions.java failed with "RuntimeException: 'prop[boo] = >foo<' missing from stdout/stderr"

Reviewed-by: goetz
Backport-of: d63388c
  • Loading branch information
Andrew Lu authored and GoeLin committed Oct 15, 2023
1 parent 94d3648 commit c780db7
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 25 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2021, 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
Expand Down Expand Up @@ -474,11 +474,10 @@ private void dumpStream(InputStream stream) throws IOException {
// printDirect()
}
} catch (IOException ex) {
String s = ex.getMessage();
if (!s.startsWith("Bad file number")) {
if (!ex.getMessage().equalsIgnoreCase("stream closed")) {
throw ex;
}
// else we got a Bad file number IOException which just means
// else we got a "Stream closed" IOException which just means
// that the debuggee has gone away. We'll just treat it the
// same as if we got an EOF.
}
Expand Down
71 changes: 50 additions & 21 deletions test/jdk/com/sun/jdi/JdbOptions.java
Expand Up @@ -34,9 +34,17 @@
import lib.jdb.JdbCommand;
import jdk.test.lib.process.OutputAnalyzer;

import java.io.IOException;
import java.io.PrintStream;
import java.lang.management.ManagementFactory;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;

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

public static void main(String[] args) {
System.out.println(OK_MSG);
// print all args
List<String> vmArgs = ManagementFactory.getRuntimeMXBean().getInputArguments();
for (String s: vmArgs) {
System.out.println(argString(s));
}
// print requested sys.props
for (String p: args) {
System.out.println(propString(p, System.getProperty(p)));
/**
* 1st argument is a filename to redirect application output,
* the rest are names of the properties to dump.
*/
public static void main(String[] args) throws IOException {
String outFile = args[0];
try (PrintStream out = new PrintStream(outFile, StandardCharsets.UTF_8)) {
out.println(OK_MSG);
// print all args
List<String> vmArgs = ManagementFactory.getRuntimeMXBean().getInputArguments();
for (String s : vmArgs) {
out.println(argString(s));
}
// print requested sys.props (skip 1st arg which is output filename)
for (int i=1; i < args.length; i++) {
String p = args[i];
out.println(propString(p, System.getProperty(p)));
}
}
}
}

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

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

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

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

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

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

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

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

Expand All @@ -120,7 +143,7 @@ public static void main(String[] args) throws Exception {
+ " -XX:+IgnoreUnrecognizedVMOptions"
+ " \"-XX:StartFlightRecording=dumponexit=true,maxsize=500M\""
+ " '-XX:FlightRecorderOptions=repository=jfrrep'"
+ ",main=" + targ + " prop1 prop2 prop3 prop4")
+ ",main=" + targ + " " + outFilename + " prop1 prop2 prop3 prop4")
.expectedProp("prop1", "val1")
.expectedProp("prop2", "val 2")
.expectedProp("prop3", "val3")
Expand Down Expand Up @@ -154,12 +177,18 @@ private static TestResult test(String... args) throws Exception {
.map(s -> s.replace("\"", "\\\""))
.toArray(String[]::new);
}

try (Jdb jdb = new Jdb(args)) {
jdb.waitForSimplePrompt(1024, true); // 1024 lines should be enough
jdb.command(JdbCommand.run().allowExit());
OutputAnalyzer out = new OutputAnalyzer(jdb.getJdbOutput());
out.shouldContain(JbdOptionsTarg.OK_MSG);
return new TestResult(out);
}
String output = Files.readAllLines(outPath, StandardCharsets.UTF_8).stream()
.collect(Collectors.joining(System.getProperty("line.separator")));
Files.deleteIfExists(outPath);
System.out.println("Debuggee output: [");
System.out.println(output);
System.out.println("]");
OutputAnalyzer out = new OutputAnalyzer(output);
return new TestResult(out);
}
}

1 comment on commit c780db7

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.