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

ImageReader.read does not throw IIOException when destination is incompatible

    XMLWordPrintable

    Details

      Description

      There is a method setDestination() in ImageReadParam which can be used to
      specify a destination image. As per the specification, this must be one of the types returned by ImageReader.getImageTypes(). The API doc of setDestination() claims that if the image specified by this method does not use the sample model and color model used by one of the type specifiers returned by getImageTypes(), read() method would throw an IIOException. But If i specify a buffered image
      type which uses a different color model and sample model, read() method either throws IllegalArgException saying the bands on source and destination mismatch or it throws a ClassCastException.

      For JPEG and PNG, it throws IllegalArgumentException. for GIF, it throws ClassCastException. For BMP, it throws NullPointerException. But I don't see any IIOException being thrown. It would be great if all these readers are made consistant in handling an incompatible destination. However the NPE thrown by BMP ImageReader is weird and must be more meaningful.

      Though the API doc for read() method claims that it would throw an IllegalArgException it is conflicting with setDestination() method which tells the user that it would throw an IIOException. Either it must be fixed or the doc must be modified.

      This bug is reproducible since JDK1.4+ on Win32 as well as Solaris platforms.

      I have attached a sample code. Execute the sample code as follows.
      java SetDestinationTest <img file>. Ex: java SetDestinationTest cup.png
      You will see a frame with a drop-down at the bottom. Choose the buffered image types one by one and you will see various exceptions in the console.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              bae Andrew Brygin
              Reporter:
              pmohansunw Praveen Mohan (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: