[OpenJDK 2D-Dev] FileCacheImageOutputStream.close() is not idempotent

Phil Race philip.race at oracle.com
Thu Jun 14 16:59:59 UTC 2012

On 6/14/2012 9:37 AM, Martin Desruisseaux wrote:
> Hello all
> This is (as far as I remember) my first post on this mailing list. I 
> would like to know if the Java2D team has a JIRA bug tracker for 
> reporting issues, like the JavaFX team? Anyway there is a first issue 
> I would like to submit:

The JDK team overall doesn't (yet) use JIRA. Report bugs at bugs.sun.com

> javax.imageio.stream.FileCacheImageOutputStream throws a 
> NullPointerException if the close() method is invoked twice. This 
> behaviour does not comply with the java.io.Closeable specification, 
> which said "If the stream is already closed then invoking this method 
> has no effect.". The NullPointerException is caused by the close() 
> method setting the 'cache' field to null, while the first line of the 
> 'close()' method does not verify if the cache is already null.

> A similar issue apply to FileCacheImageInputStream, except that in 
> this case the code explicitly throws an IOException if the stream is 
> already closed. Again this is in contradiction with the Closeable 
> specification (note that nothing in the ImageInputStream specification 
> said that the close() method should behave that way). So I leave the 
> FileCacheImageInputStream.close() issue as an open question for now...

Closeable was retro-fitted to these APIs in JDK 7 to support ARM.
and the change was implemented under bug
6911258 : Project Coin: Add essential API support for Automatic Resource 
Management (ARM) blocks

Perhaps the real issue is that the interface Closeable should not have made
claims about what all the existing close methods it was added to do in 
all cases.
FileInputStream.close() made no such claim.

I think maybe you should post on the core-libs list asking if the spec. 
for Closeable should
be up for revision here.


> Proposed patch attached for FileImageOutputStream.
>     Regards,
>         Martin

More information about the 2d-dev mailing list