JDK-4895467 : JPEG Writer throws an IIOException when trying to reuse it
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.imageio
  • Affected Version: 1.4.0
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2003-07-24
  • Updated: 2003-12-19
  • Resolved: 2003-09-15
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other Other
1.4.2_18-revFixed 1.4.2_19Fixed
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
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger FIXED IN: tiger INTEGRATED IN: tiger tiger-b20 VERIFIED IN: tiger-beta
14-06-2004

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
26-08-2003