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

Jaikiran Pai jpai at openjdk.org
Sun Sep 28 08:56:32 UTC 2025


On Mon, 22 Sep 2025 22:25:59 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:
> 
>   Update close() to use "terminate" consistently.

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

> 235:     // If an IOException occurs and it is the first, return it.
> 236:     // Otherwise, add the exception as a suppressed exception to the first.
> 237:     private IOException quietClose(Closeable c, IOException firstIOE) {

Nit - I think this can be a `static` method.

test/jdk/java/lang/Process/ProcessCloseTest.java line 54:

> 52: /*
> 53:  * @test
> 54:  * @bug 8336479

Hello Roger, this could be a copy/paste error - the bug id looks incorrect on this new test.

test/jdk/java/lang/Process/ProcessCloseTest.java line 68:

> 66:         String JAVA_HOME = System.getProperty("test.jdk");
> 67:         if (JAVA_HOME == null)
> 68:             JAVA_HOME = System.getProperty("JAVA_HOME");

Should we instead just rely on the standard `java.home` property instead of these conditionals? i.e. `System.getProperty("java.home")`?

test/jdk/java/lang/Process/ProcessCloseTest.java line 70:

> 68:             JAVA_HOME = System.getProperty("JAVA_HOME");
> 69:         String classPath = System.getProperty("test.class.path");
> 70:         return  List.of(JAVA_HOME + "/bin/java", "-cp", classPath, ProcessCloseTest.class.getName());

The method name says `setupJavaEXE()`. Was this line here expected to conditionally use `.exe` suffix for Windows, like some other tests do?

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

PR Review Comment: https://git.openjdk.org/jdk/pull/26649#discussion_r2385085622
PR Review Comment: https://git.openjdk.org/jdk/pull/26649#discussion_r2385082121
PR Review Comment: https://git.openjdk.org/jdk/pull/26649#discussion_r2385093199
PR Review Comment: https://git.openjdk.org/jdk/pull/26649#discussion_r2385100632


More information about the core-libs-dev mailing list