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

JPGWriter.getDefaultImageMetadata throws internal error when image type is null

    XMLWordPrintable

Details

    Description

      The API doc for ImageWriter.getDefaultImageMetadata() does not really specify what is the consequence of passing a null value for the image type parameter. JPG Writer throws an Internal Error where as other image formats throws a NPE when imagetype parameter is null. This has to be made consistant. All metadata related methods in ImageReader specify that an IllegalArgException would be thrown for such circumstances and it can be done for ImageWriter also. Though NULL is not a valid value, it would be better to throw some exception instead of throwing an Internal Error.

      Since the output of this method depends on this input value, it must be documented precisely saying an IllegalArgException will be thrown if the image type parameter is null so as to define the dependency of this API on the input value.

      This is reproducible on all platforms since JDK1.4.

      I have attached a sample testcase. Execute the sample testcase and you would notice the following internal error:
      Exception in thread "main" java.lang.InternalError: Default image metadata is inconsistent
      at com.sun.imageio.plugins.jpeg.JPEGMetadata.<init>(JPEGMetadata.java:615)
      at com.sun.imageio.plugins.jpeg.JPEGImageWriter.getDefaultImageMetadata(JPEGImageWriter.java:185)
      at WriterMetadataErrorTest.<init>(WriterMetadataErrorTest.java:21)
      at WriterMetadataErrorTest.main(WriterMetadataErrorTest.java:33)

      Attachments

        Issue Links

          Activity

            People

              jdv Jayathirth D V
              pmohansunw Praveen Mohan (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Imported:
                Indexed: