RFR: 8364361: [process] java.lang.Process should implement Closeable [v11]
Naoto Sato
naoto at openjdk.org
Fri Sep 26 22:16:22 UTC 2025
On Mon, 22 Sep 2025 22:25:59 GMT, Roger Riggs <rriggs at openjdk.org> wrote:
>> The teardown of a Process launched by `ProcessBuilder` includes the closing of streams and ensuring the termination of the process is the responsibility of the caller. The `Process.close()` method provides a clear and obvious way to ensure all the streams are closed and the process terminated.
>>
>> The try-with-resources statement is frequently used to open streams and ensure they are closed on exiting the block. By implementing `AutoClosable.close()` the completeness of closing the streams and process termination can be done by try-with-resources.
>>
>> The actions of the `close()` method are to close each stream and destroy the process if it has not terminated.
>
> Roger Riggs has updated the pull request incrementally with one additional commit since the last revision:
>
> Update close() to use "terminate" consistently.
Looks good to me. Left some minor comments.
src/java.base/share/classes/java/lang/Process.java line 189:
> 187: * The contents of streams that have not been read fully are lost,
> 188: * they are discarded or ignored.
> 189: * Streams should be {@code closed} when no longer needed.
Why is this `closed` in "@code" tag?
src/java.base/share/classes/java/lang/snippet-files/ProcessExamples.java line 39:
> 37: // Read all lines and print each
> 38: reader.readAllLines()
> 39: .forEach(System.err::println);
Is it intentional to use `System.err`?
test/jdk/java/lang/Process/ProcessCloseTest.java line 93:
> 91: * - A List of ProcessCommand actions to be invoked on that process
> 92: * - A expected final ExitStatus
> 93: * @return
Dangling @return
test/jdk/java/lang/Process/ProcessCloseTest.java line 379:
> 377: }
> 378:
> 379: // Process.processExpectExitNormal an expected status
Comment does not seem to reflect the method
test/jdk/java/lang/Process/ProcessCloseTest.java line 514:
> 512: * @param exitStatus The expected final exit status
> 513: */
> 514: @ParameterizedTest()
Extra ()s
test/jdk/java/lang/Process/ProcessCloseTest.java line 574:
> 572: * On Linux, the existing fd is closed to prevent a leak and the fd is replaced by a bad fd.
> 573: * On Windows, the existing handle is closed
> 574: * @param an OutputStream from Process.getOutputStream
Comment seems to refer to output stream
-------------
Marked as reviewed by naoto (Reviewer).
PR Review: https://git.openjdk.org/jdk/pull/26649#pullrequestreview-3273956517
PR Review Comment: https://git.openjdk.org/jdk/pull/26649#discussion_r2383510138
PR Review Comment: https://git.openjdk.org/jdk/pull/26649#discussion_r2383496131
PR Review Comment: https://git.openjdk.org/jdk/pull/26649#discussion_r2383543929
PR Review Comment: https://git.openjdk.org/jdk/pull/26649#discussion_r2383575835
PR Review Comment: https://git.openjdk.org/jdk/pull/26649#discussion_r2383579667
PR Review Comment: https://git.openjdk.org/jdk/pull/26649#discussion_r2383586192
More information about the core-libs-dev
mailing list