On Fri, 31 Oct 2025 14:32:24 GMT, Roger Riggs <[email protected]> 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 two additional 
> commits since the last revision:
> 
>  - Correct reference to ProcessExamples.java to use the `file` tag.
>  - Miscellaneous javadoc improvements suggested by reviewers.
>    Updated the example program to be a standalone program as might be run
>    as a compact source file main program.

I think you've got this feature in a good place. It is definitely one of the 
difficult APIs to retrofit.

src/java.base/share/classes/java/lang/Process.java line 121:

> 119:  * or readers, or they have been closed. The Process {@linkplain 
> Process#close close} method closes
> 120:  * all the streams and terminates the process to release the resources. 
> Using try-with-resources to
> 121:  * {@linkplain ProcessBuilder#start() start} the process can ensure the 
> process

I think it would be simpler if you drop the ProcessBuilder.start from this 
sentence, it need only say that using the try-with-resources statement will 
ensure the process is terminated.

src/java.base/share/classes/java/lang/Process.java line 199:

> 197:      * <p>
> 198:      * After the streams are closed this method {@linkplain #waitFor() 
> waits for} the
> 199:      * process to terminate. If interrupted while {@linkplain #waitFor() 
> waiting}

You can link "interrupted" to Thread.interrupt, no need for the second linking 
to waitFor as the first sentence establishes that the method waits and links to 
waitFor.

src/java.base/share/classes/java/lang/Process.java line 205:

> 203:      * any {@code IOExceptions} are thrown.
> 204:      * <p>
> 205:      * Try-with-resources example to write text to a process, read back 
> the

`@apiNote` ?

src/java.base/share/classes/java/lang/Process.java line 216:

> 214:      * The {@code outputWriter} and {@code outputStream} to the process 
> are closed.
> 215:      * The {@code inputReader} and {@code inputStream} from the process 
> are closed.
> 216:      * The {@code errorReader} and {@code errorStream} from the process 
> are closed.

I mentioned this previously but you can collapse these 3 sentences into one. If 
you want to specify the ordering (I don't it needs to) then it can say this, no 
ordering is implied now.

-------------

PR Review: https://git.openjdk.org/jdk/pull/26649#pullrequestreview-3406947587
PR Review Comment: https://git.openjdk.org/jdk/pull/26649#discussion_r2483192427
PR Review Comment: https://git.openjdk.org/jdk/pull/26649#discussion_r2483190247
PR Review Comment: https://git.openjdk.org/jdk/pull/26649#discussion_r2483190680
PR Review Comment: https://git.openjdk.org/jdk/pull/26649#discussion_r2483191329

Reply via email to