RFR: 8364361: [process] java.lang.Process should implement Closeable [v17]
Alan Bateman
alanb at openjdk.org
Fri Oct 17 11:35:11 UTC 2025
On Fri, 17 Oct 2025 01:46:48 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:
>
> Incremental update to make it clear that if it is necessary
> to forcibly destroy the process, close continues to wait for the
> process to terminate.
src/java.base/share/classes/java/lang/Process.java line 180:
> 178:
> 179: /**
> 180: * Close all writer and reader streams immediately and wait for the process to terminate.
It might read a bit better to say "reader and write streams" and drop the word immediately.
src/java.base/share/classes/java/lang/Process.java line 194:
> 192: * Closing an already closed stream usually has no effect but is specific to the stream.
> 193: * If an {@code IOException} occurs when closing a stream it is thrown
> 194: * when this method returns. Additional {@code IOExceptions}
What would you think of replacing "when this method returns" with "after the process has terminated"?
src/java.base/share/classes/java/lang/Process.java line 201:
> 199: * process to terminate. If interrupted while {@linkplain #waitFor waiting for termination}
> 200: * the process is {@linkplain #destroyForcibly() forcibly destroyed} and continues to wait
> 201: * for the process to terminate.
"and continues to wait" would be clearer if expanded to "and this method continues to wait ..."
src/java.base/share/classes/java/lang/Process.java line 247:
> 245:
> 246: // Wait for the process to terminate, return true if the wait is interrupted.
> 247: private boolean waitForInterrupted() {
tryWait that returns true when wait completes?
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/26649#discussion_r2439481775
PR Review Comment: https://git.openjdk.org/jdk/pull/26649#discussion_r2439484992
PR Review Comment: https://git.openjdk.org/jdk/pull/26649#discussion_r2439489107
PR Review Comment: https://git.openjdk.org/jdk/pull/26649#discussion_r2439493529
More information about the core-libs-dev
mailing list