Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8291986

ProcessBuilder.redirectErrorStream(true) leaves error stream available

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 25
    • core-libs
    • None

      When launching a Process using ProcessBuilder, the standard error output can be redirected to be merged with the standard output using ProcessBuilder.redirectErrorStream(true). The implementation on Linux duplicates the file descriptor for stdout to stderr so output written to stderr appears on stdout.

      A pipe for stderr is created in the parent process consisting of a pair of file descriptors. When redirectErrorStream is true, the fd the subprocess writes to is ignored in the child and closed in the parent so the stream is empty. The fd for reading the process stderr is left open and can be retrieved with `getErrorStream()`. Since the write side has been closed, reading from the stream reports end-of-file. The stream returned from getErrorStream is not used (typically) and is equivalent in function to NullInputStream.

      Leaving the error stream and file descriptor open is benign and not likely to be noticed except for the stream and fd that will be left open until it becomes unreferenced and its cleanup code is run to close it. The cleanup occurs at a non-deterministic time based on GC cycles.

      A more predictable implementation could, in the case of `redirectErrorStream`, avoid creating the pipe and return a NullInputStream when Process.getErrorStream() is called.



            rriggs Roger Riggs
            rriggs Roger Riggs
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: