RFR: 8354872: Clarify java.lang.Process resource cleanup
Jaikiran Pai
jpai at openjdk.org
Fri Jun 27 16:11:47 UTC 2025
On Wed, 18 Jun 2025 20:16:18 GMT, Roger Riggs <rriggs at openjdk.org> wrote:
> Improve the documentation of Process use of system resources.
>
> Describe the implementation closing streams when no longer referenced.
> Clarify the interactions between inputStream and inputReader and errorStream and errorReader.
> Add advice and example using try-with-resources to open and close streams.
> Recommend closing streams when no longer in use.
src/java.base/share/classes/java/lang/Process.java line 202:
> 200: *
> 201: * @apiNote
> 202: * Avoid using both {@link #getInputStream} and {@link #inputReader(Charset)}.
The reworded sentence I think is still a bit confusing. In the new proposed form, it sounds like both these methods are to be avoided. I think the intention of this apiNote is to convey that they should not be invoked on the same Process instance. Would something like the following be clear and accurate:
>
> Either use {@link #getInputStream} or {@link #inputReader(Charset)} but not both on the same {@code Process}.
> ...
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/25884#discussion_r2172354098
More information about the core-libs-dev
mailing list