-
Bug
-
Resolution: Fixed
-
P4
-
None
-
1.4.2
-
x86
-
windows_xp
FULL PRODUCT VERSION :
java version "1.5.0"
ADDITIONAL OS VERSION INFORMATION :
Windows XP
A DESCRIPTION OF THE PROBLEM :
The code in ImageIO.CanDecodeInputFilter#filter(Object) does not reset the ImageInputStream used to filter when an ImageReaderSpi throws an exception during checks to see if it can decode the stream.
The code is as follows:
public boolean filter(Object elt) {
try {
ImageReaderSpi spi = (ImageReaderSpi)elt;
ImageInputStream stream = null;
if (input instanceof ImageInputStream) {
stream = (ImageInputStream)input;
}
// Perform mark/reset as a defensive measure
// even though plug-ins are supposed to take
// care of it.
boolean canDecode = false;
if (stream != null) {
stream.mark();
}
canDecode = spi.canDecodeInput(input);
if (stream != null) {
stream.reset();
}
return canDecode;
} catch (IOException e) {
return false;
}
}
}
The section that resets the stream should be in a "finally" block to catch the occasions when spi.canDecodeInput(input) throws an IOException.
I've received this problem when processing certain PNM files.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Execute the code below with an image that will trigger an IOException from an ImageReaderSpi, and see how no ImageReader instances are returned. You can step into the code at the line ImageIO.getImageReaders() and follow through to CanDecodeFilter#filter() to see how the ImageInputStream is not reset when an exception is thrown during spi.canDecodeInput().
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
An ImageReader instance is returned for the image.
ACTUAL -
No ImageReader instance is returned.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public static void main (String[] args)
{
File f = new File("C:\\notworking0.pbm");
// Get all the ImageReader instances for the File.
FileImageInputStream fiis = new FileImageInputStream(f);
Iterator imageReaders = ImageIO.getImageReaders(fiis);
ImageReader reader = null;
// We just want the first ImageReader.
if (imageReaders.hasNext())
{
reader = (ImageReader) imageReaders.next();
// Close the filter stream.
fiis.close();
ImageInputStream inputStream = new FileImageInputStream(f);
reader.setInput(inputStream);
System.out.println("Found " + reader.getClass().getName());
}
else
{
// If we haven't got anything to return
System.out.println("No ImageReader found.");
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Wrap a class around ImageIO that provides an implementation for getImageReaders() which has code similar to ImageIO but does not fall in
java version "1.5.0"
ADDITIONAL OS VERSION INFORMATION :
Windows XP
A DESCRIPTION OF THE PROBLEM :
The code in ImageIO.CanDecodeInputFilter#filter(Object) does not reset the ImageInputStream used to filter when an ImageReaderSpi throws an exception during checks to see if it can decode the stream.
The code is as follows:
public boolean filter(Object elt) {
try {
ImageReaderSpi spi = (ImageReaderSpi)elt;
ImageInputStream stream = null;
if (input instanceof ImageInputStream) {
stream = (ImageInputStream)input;
}
// Perform mark/reset as a defensive measure
// even though plug-ins are supposed to take
// care of it.
boolean canDecode = false;
if (stream != null) {
stream.mark();
}
canDecode = spi.canDecodeInput(input);
if (stream != null) {
stream.reset();
}
return canDecode;
} catch (IOException e) {
return false;
}
}
}
The section that resets the stream should be in a "finally" block to catch the occasions when spi.canDecodeInput(input) throws an IOException.
I've received this problem when processing certain PNM files.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Execute the code below with an image that will trigger an IOException from an ImageReaderSpi, and see how no ImageReader instances are returned. You can step into the code at the line ImageIO.getImageReaders() and follow through to CanDecodeFilter#filter() to see how the ImageInputStream is not reset when an exception is thrown during spi.canDecodeInput().
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
An ImageReader instance is returned for the image.
ACTUAL -
No ImageReader instance is returned.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public static void main (String[] args)
{
File f = new File("C:\\notworking0.pbm");
// Get all the ImageReader instances for the File.
FileImageInputStream fiis = new FileImageInputStream(f);
Iterator imageReaders = ImageIO.getImageReaders(fiis);
ImageReader reader = null;
// We just want the first ImageReader.
if (imageReaders.hasNext())
{
reader = (ImageReader) imageReaders.next();
// Close the filter stream.
fiis.close();
ImageInputStream inputStream = new FileImageInputStream(f);
reader.setInput(inputStream);
System.out.println("Found " + reader.getClass().getName());
}
else
{
// If we haven't got anything to return
System.out.println("No ImageReader found.");
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Wrap a class around ImageIO that provides an implementation for getImageReaders() which has code similar to ImageIO but does not fall in
- duplicates
-
JDK-8144071 ImageIO does not reset stream if an exception is thrown
- Resolved