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

Roger Riggs rriggs at openjdk.org
Wed Oct 8 14:06:44 UTC 2025


On Wed, 8 Oct 2025 13:59:39 GMT, Jason Mehrens <duke at openjdk.org> wrote:

>> src/java.base/share/classes/java/lang/Process.java line 235:
>> 
>>> 233:                 destroyForcibly();
>>> 234:                 // Re-assert the interrupt
>>> 235:                 Thread.currentThread().interrupt();
>> 
>> I think this is still problematic as code after the t-w-r can't be guaranteed that the child has terminated. So I think it needs a loop that ends when waitFor completes without an exception (destroyForcibly would only be called on the first interrupt of course).
>
> I also wonder if close of streams should happen after first wait on destroy or on interruption. I'm thinking the difference is that streams would still be usable to fetch buffered data.

Looping could still lead to an infinite hang if the process never dies.
For example, some Unix processes can stay around as zombie's even after kill -9 if they don't get reap'ed.
On Windows, some files can't be closed and the processes hang around indefinitely.
Tracking down those dependencies and resolving them is outside of the Java scope.
I don't think the contract for T-W-R/close has guarantee the process has gone away, only that it has been destroyed (forcibly).

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

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


More information about the core-libs-dev mailing list