Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8364135

JPEGImageReader.getImageTypes() should throw exception for non-zero image index

XMLWordPrintable

    • Fix Understood
    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      com.sun.imageio.plugins.jpeg.JPEGImageReader.getImageTypes(-1) without input source returns an empty iterator instead of throwing an exception
      IllegalStateException – if the input source has not been set.
      IndexOutOfBoundsException – if the supplied index is out of bounds.
      IOException – if an error occurs reading the format information from the input source.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      catch Exception
      ACTUAL -
      class com.sun.imageio.plugins.jpeg.JPEGImageReader
      false

      ---------- BEGIN SOURCE ----------
      import java.io.IOException;
      import java.util.Iterator;

      import javax.imageio.ImageIO;
      import javax.imageio.ImageReader;

      public class JpegReaderTest {

          public static void main(String[] args) {
              Iterator<ImageReader> readers = ImageIO.getImageReadersByFormatName("jpeg");
              if (!readers.hasNext()) {
                  throw new RuntimeException("No jpeg image readers found");
              }

              ImageReader ir = readers.next();
              System.out.println(ir.getClass());
              try {
                  Iterator types = ir.getImageTypes(-1);
                  System.out.println(types.hasNext());
              } catch (IOException | IndexOutOfBoundsException | IllegalStateException e) {
                  System.out.println(e.getMessage()); // expectied
              }
          }
      }

      ---------- END SOURCE ----------

            jdv Jayathirth D V
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: