RFR: 8364361: [process] java.lang.Process should implement close and be AutoCloseable [v6]
Roger Riggs
rriggs at openjdk.org
Wed Sep 3 21:40:45 UTC 2025
On Wed, 3 Sep 2025 19:00:26 GMT, David Lloyd <dmlloyd at openjdk.org> wrote:
>> Roger Riggs has updated the pull request incrementally with one additional commit since the last revision:
>>
>> javadoc tweaks
>
> src/java.base/share/classes/java/lang/Process.java line 664:
>
>> 662: ioe = quietClose(errorReader != null ? errorReader : getErrorStream(), ioe);
>> 663:
>> 664: destroy(); // no-op if process is not alive
>
> On some platforms, `destroy` and `destroyForcibly` behave differently. That means `close` would also behave differently depending on the platform. Maybe it should either always call `destroyForcibly` or else only call `destroy` if `supportsNormalTermination` (and otherwise hope that closing the streams is a good enough hint) to be consistent?
`DestroyForcibly` is an escalation that should only be used with a known poorly behaved process; and that's up to the programmer. It is the equivalent of `kill -9`.
It should not be used in the normal case. Unfortunately, Windows does not have a polite, please terminate API so `destroy` has the same behavior as `destroyForcibly`.
If the caller uses `process.waitFor()` within the try-catch, the process will have terminated, possibly based on the stream closings, and `destroy()` will not be called.
If emphasis is needed, the javadoc can elaborate.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/26649#discussion_r2320282535
More information about the core-libs-dev
mailing list