JDK-8303698 : ProcessTools.startProcess(...) drains output streams silently.
  • Type: Bug
  • Component: hotspot
  • Sub-Component: test
  • Affected Version: 21
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • Submitted: 2023-03-06
  • Updated: 2023-04-20
  • Resolved: 2023-04-20
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 21
21Resolved
Related Reports
Duplicate :  
Description
The 
ProcessTools.startProcess(...) 
drains output streams and it might cause problems for tests trying to read output for this process.

The possible solution would be either to try to duplicate streams for ProcessImpl created with ProcessTools.startProcess(...) or to explicitly throw exception. 

Also, it might be required to fix all tests with the pattern:
    Process p = ProcessTools.startProcess("..");
    p.waitFor();
    OutputAnalyzer out = new OutputAnalyzer(p);

Here is the example of the problem:

import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;

public class Main {


    public static void main(String[] args) throws Exception {
        if (args.length > 0) {
            System.out.print(args[0]);
            return;
        }
        // Needed to set property if run without using jtreg.
        System.setProperty("test.jdk", "/Users/lmesnik/tools/jdk-19/macosx-x64");
        {
            Process p = ProcessTools.createJavaProcessBuilder(Main.class.getName(), "ARG1\n").start();
            p.waitFor();

            OutputAnalyzer out = new OutputAnalyzer(p);
            out.reportDiagnosticSummary();
        }

        {
            Process p = ProcessTools.startProcess("process",ProcessTools.createJavaProcessBuilder(Main.class.getName(), "ARG2\n"));
            p.waitFor();

            OutputAnalyzer out = new OutputAnalyzer(p);
            out.reportDiagnosticSummary();
        }
    }
}

The ouput:
Command line: [/Users/lmesnik/tools/jdk-19/macosx-x64/bin/java -cp /Users/lmesnik/IdeaProjects/tests/out/production/tests Main ARG1
 ]
[2023-03-06T22:57:45.968145Z] Gathering output for process 28704
[2023-03-06T22:57:46.004649Z] Waiting for completion for process 28704
[2023-03-06T22:57:46.004776Z] Waiting for completion finished for process 28704
Command line: [/Users/lmesnik/tools/jdk-19/macosx-x64/bin/java -cp /Users/lmesnik/IdeaProjects/tests/out/production/tests Main ARG2
 ]
[process]:/Users/lmesnik/tools/jdk-19/macosx-x64/bin/java -cp /Users/lmesnik/IdeaProjects/tests/out/production/tests Main ARG2

[2023-03-06T22:57:46.019328Z] Gathering output for process 28705
 stdout: [ARG1
];
 stderr: []
 exitValue = 0

[process] ARG2
[2023-03-06T22:57:46.108352Z] Waiting for completion for process 28705
[2023-03-06T22:57:46.108643Z] Waiting for completion finished for process 28705
 stdout: [];
 stderr: []
 exitValue = 0