-
Bug
-
Resolution: Duplicate
-
P4
-
6u10, 7, 8
-
generic
-
generic
FULL PRODUCT VERSION :
java version "1.6.0_12"
Java(TM) SE Runtime Environment (build 1.6.0_12-b04)
Java HotSpot(TM) 64-Bit Server VM (build 11.2-b01, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.0.6001]
A DESCRIPTION OF THE PROBLEM :
The Javadoc for ImageReader says to use IndexOutOfBoundsException to detect the end of the images, except that JPEGImageReader violates this by not throwing IndexOutOfBoundsException at the end of the list of images.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the attached test case.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Test should pass. If you call it, getNumImages(true) returns 1 so only the image at index 0 (= getMinIndex()) should exist.
ACTUAL -
Test actually fails because the reader returns image 0 when you ask for image 1. Additionally, the reader takes an *enormous* amount of time to determine that there is no image at index 2!
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.io.File;
import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import javax.imageio.stream.ImageInputStream;
import org.junit.Test;
public class TestJpeg {
@Test
public void test() throws Exception {
ImageInputStream stream = ImageIO.createImageInputStream(new File("D:\\TMP.001.001.0002.JPG"));
ImageReader imageReader = ImageIO.getImageReaders(stream).next();
imageReader.setInput(stream);
int count = 0;
for (int index = imageReader.getMinIndex(); ; index++) {
try {
imageReader.read(index);
count++;
} catch (IndexOutOfBoundsException e) {
// Break the loop on IndexOutOfBoundsException as recommended by ImageIO javadoc.
break;
}
}
assertEquals("Wrong number of images", 1, count);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Workaround is to call getNumImages(true) up-front to determine the number of images, and then trusting that number. The penalty is that you may have to read the entire image twice, and the Javadoc itself says not to call that method if you care about performance.
java version "1.6.0_12"
Java(TM) SE Runtime Environment (build 1.6.0_12-b04)
Java HotSpot(TM) 64-Bit Server VM (build 11.2-b01, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.0.6001]
A DESCRIPTION OF THE PROBLEM :
The Javadoc for ImageReader says to use IndexOutOfBoundsException to detect the end of the images, except that JPEGImageReader violates this by not throwing IndexOutOfBoundsException at the end of the list of images.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the attached test case.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Test should pass. If you call it, getNumImages(true) returns 1 so only the image at index 0 (= getMinIndex()) should exist.
ACTUAL -
Test actually fails because the reader returns image 0 when you ask for image 1. Additionally, the reader takes an *enormous* amount of time to determine that there is no image at index 2!
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.io.File;
import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import javax.imageio.stream.ImageInputStream;
import org.junit.Test;
public class TestJpeg {
@Test
public void test() throws Exception {
ImageInputStream stream = ImageIO.createImageInputStream(new File("D:\\TMP.001.001.0002.JPG"));
ImageReader imageReader = ImageIO.getImageReaders(stream).next();
imageReader.setInput(stream);
int count = 0;
for (int index = imageReader.getMinIndex(); ; index++) {
try {
imageReader.read(index);
count++;
} catch (IndexOutOfBoundsException e) {
// Break the loop on IndexOutOfBoundsException as recommended by ImageIO javadoc.
break;
}
}
assertEquals("Wrong number of images", 1, count);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Workaround is to call getNumImages(true) up-front to determine the number of images, and then trusting that number. The penalty is that you may have to read the entire image twice, and the Javadoc itself says not to call that method if you care about performance.
- duplicates
-
JDK-8152672 IIOException while getting second image properties for JPEG
-
- Resolved
-