RFR: JDK-8302281 - ImageIO objects should implement AutoClosable

Glavo duke at openjdk.org
Sun Feb 12 01:31:34 UTC 2023


On Thu, 19 Jan 2023 18:41:08 GMT, Markus KARG <duke at openjdk.org> wrote:

> ImageIO objects, like ImageReader, ImageWrite, ImageInputStream and ImageOutputStream, should implement AutoClosable.
> 
> There is a risk of keeping resources opened longer than needed (or even run into a resource leak with long running processes) as the user cannot use try-with-resources currently. The fact that there is a `dispose()` method to be called is easily missed, as people tend to look for `close()`.
> 
> This is not a big change, but it is useful for those working with ImageIO.

src/java.desktop/share/classes/javax/imageio/ImageReader.java line 2883:

> 2881:      * @implNote The default implementation of this method invokes {@link #dispose()}.
> 2882:      */
> 2883:     public void close() {

(Not a reviewer) I think we need to add the `@since` tag to javadoc.

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

PR: https://git.openjdk.org/jdk/pull/12098



More information about the client-libs-dev mailing list