United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-4895467 JPEG Writer throws an IIOException when trying to reuse it
JDK-4895467 : JPEG Writer throws an IIOException when trying to reuse it

Details
Type:
Bug
Submit Date:
2003-07-24
Status:
Closed
Updated Date:
2003-12-19
Project Name:
JDK
Resolved Date:
2003-09-15
Component:
client-libs
OS:
generic
Sub-Component:
javax.imageio
CPU:
generic
Priority:
P3
Resolution:
Fixed
Affected Versions:
1.4.0
Fixed Versions:
5.0 (tiger)

Related Reports
Backport:
Backport:

Sub Tasks

Description
I am creating a JPEG writer and writing a TYPE_INT_RGB image to a file. After this, i am calling writer.reset(). I am creating a new ImageOutputStream (out of a newly created file) and setting it to the same writer and using the same writer to write another buffered image which is of type TYPE_INT_ARGB. In this case, I am getting an IIOException saying Metadata components are not equal to number of destination bands. The above scenario works fine if both the images are either RGB or ARGB. Unable to write a RGB after ARGB and vice versa.

Any ImageWriter must be reusable and the user should not be expected to create a new writer for each write operation. In the above scenario, the only workaround is to create the JPEGWriter again and the existing writer could not be reused to write another image inspite of restoring it to its initial state. 

This is reproducible on Solaris and Win32 right from JDK1.4+.

I have attached a sample code. Execute the same application as follows.
java WriterReuseTest <imgformat> 
This will throw an IIOException at the console.

The exception thrown:
javax.imageio.IIOException: Metadata components != number of destination bands
 at com.sun.imageio.plugins.jpeg.JPEGImageWriter.checkSOFBands(JPEGImageWriter.java:1162)
 at com.sun.imageio.plugins.jpeg.JPEGImageWriter.write(JPEGImageWriter.java:611)
 at javax.imageio.ImageWriter.write(ImageWriter.java:591)
 at WriterReuseTest.<init>(WriterReuseTest.java:69)
 at WriterReuseTest.main(WriterReuseTest.java:101)

                                    

Comments
EVALUATION

We keep an instance variable called "metadata" that is used to reference the
JPEGMetadata across various methods during the write process.  The problem
here is that we don't reset this state variable to null when reset() or
setOutput() is called, and then we end up using an invalid (old) value of
metadata the second time write() is called.  This would be best resolved as
part of the fix for 4868479.
###@###.### 2003-08-26
                                     
2003-08-26
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
tiger

FIXED IN:
tiger

INTEGRATED IN:
tiger
tiger-b20

VERIFIED IN:
tiger-beta


                                     
2004-06-14



Hardware and Software, Engineered to Work Together