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

Martin Desruisseaux martin.desruisseaux at geomatys.fr
Thu Jun 14 16:37:34 UTC 2012


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:

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...

Proposed patch attached for FileImageOutputStream.

     Regards,

         Martin

-------------- next part --------------
diff -r cd195e5d2c07 src/share/classes/javax/imageio/stream/FileCacheImageOutputStream.java
--- a/src/share/classes/javax/imageio/stream/FileCacheImageOutputStream.java	Fri Jun 08 12:44:30 2012 -0700
+++ b/src/share/classes/javax/imageio/stream/FileCacheImageOutputStream.java	Thu Jun 14 18:35:30 2012 +0200
@@ -222,6 +222,9 @@
      * @exception IOException if an error occurs.
      */
     public void close() throws IOException {
+        if (cache == null) {
+            return; // Stream already closed.
+        }
         maxStreamPos = cache.length();
 
         seek(maxStreamPos);


More information about the 2d-dev mailing list