RFR: 8364361: [process] java.lang.Process should implement Closeable [v11]

Roger Riggs rriggs at openjdk.org
Tue Sep 30 19:30:58 UTC 2025


On Tue, 30 Sep 2025 15:01:14 GMT, Jaikiran Pai <jpai at openjdk.org> wrote:

>> I think those warnings are already present.
>> - `process is terminated without waiting`
>> - `the caller should read the streams for any data or text and call waitFor if the exit value is needed`
>> - `Calling waitFor before calling close or exiting the try-with-resources block allows the process time to clean up and exit.`
>> - and the example calls waitFor inside the try-with-resources.
>> 
>> Does this add the emphasis you are asking for:
>> `Calling waitFor after close() or after the try-with-resources block exits returns the status after destroying the process.`
>
> I read the current proposed text a few more times. What you state is true - that it already covers the part that this method won't wait for the process to run to completion. However, I think, that detail doesn't register strongly when reading this text.
> 
> Here's what I had in mind - instead of the following sentence:
> 
> 
> * Before calling this method the caller should read the streams for any
> * data or text and call {@linkplain #waitFor() waitFor} if the exit value is needed.
> 
> 
> would something like this be appropriate:
> 
> 
>  * If the process should be allowed to run to completion, or the data from the
>  * process stream(s) or the exit value of the process is of interest, then
>  * the caller must {@linkplain #waitFor() wait} for the process to complete
>  * before calling this method. 
> 
> 
> (the rest of the text in the method doc can stay as-is) 
> 
> I think this expressly states that the applications must not call this `close()` method if they wish the process to run to completion.

Thanks for the suggested wording.  
I separated out the "data from the stream" to emphasize that it should occur before calling waitFor.
Reading data after calling waitFor could result in lost data due to buffering limitations.
Also reworded to say waitFor should not be called after close or the TWR block exits.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/26649#discussion_r2392622505


More information about the core-libs-dev mailing list