FULL PRODUCT VERSION :
java version "1.5.0_09"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_09-b01)
Java HotSpot(TM) Client VM (build 1.5.0_09-b01, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
Image works with standard ImageIO.read() and JAI-ImageIO CLibJPEGImageReader. But when the SE JPEG reader: com.sun.imageio.plugins.jpeg.JPEGImageReader is used, it throws the following exception:
javax.imageio.IIOException: ICC APP2 encountered without prior JFIF!
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Load problematic JPEG file
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
JPEG loads and can be displayed or operated on.
ACTUAL -
JPEG fails to load and throws an exception.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Caused by: javax.imageio.IIOException: ICC APP2 encountered without prior JFIF!
at com.sun.imageio.plugins.jpeg.JPEGMetadata.<init>(JPEGMetadata.java:263)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.getImageMetadata(JPEGImageReader.java:853)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.getNumThumbnails(JPEGImageReader.java:1250)
at javax.imageio.ImageReader.hasThumbnails(ImageReader.java:1608)
at com.sun.media.jai.imageioimpl.ImageReadOpImage.<init>(ImageReadOpImage.java:535)
at com.sun.media.jai.imageioimpl.ImageReadCRIF.create(ImageReadCRIF.java:309)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Iterator;
import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import javax.imageio.stream.FileImageInputStream;
public class JPEGTest {
/**
* @param args
*/
public static void main(String[] args) {
FileImageInputStream fiis = null;
try {
fiis = new FileImageInputStream(new File(args[0]));
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
if(fiis == null)
return;
Iterator<ImageReader> iter = ImageIO.getImageReaders(fiis);
ImageReader reader = null;
while (iter.hasNext()) {
reader = iter.next();
if(reader.getClass().getName().equals("com.sun.imageio.plugins.jpeg.JPEGImageReader"))
break;
}
if(reader == null)
return;
if(!reader.getClass().getName().equals("com.sun.imageio.plugins.jpeg.JPEGImageReader"))
System.out.println("com.sun.imageio.plugins.jpeg.JPEGImageReader not found, please disable reader plugin: " +
reader.getClass().toString());
reader.setInput(fiis);
try {
reader.getImageMetadata(0);
} catch (IOException e) {
e.printStackTrace();
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Do not use the SE JPEGImageReader, use the JAI-ImageIO version instead (com.sun.media.imageioimpl.plugins.jpeg.CLibJPEGImageReader)