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

com.sun.imageio.plugins.jpeg.JPEGImageReader.read() no longer throws IIOException for a bad image

XMLWordPrintable

      Java versions 8 through 18 throw a javax.imageio.IIOException when com.sun.imageio.plugins.jpeg.JPEGImageReader.read(int imageIndex, ImageReadParam param) is invoked against a bad image. However, in the latest early access version of Java 19, this call no longer throws the javax.imageio.IIOException nor does it throw any other exception. Is this an intentional change in behaviour? I checked the release notes for Java 19 https://jdk.java.net/19/release-notes but couldn't find any note about this change.

      I've attached a simple reproducer and the bad image for reproducing this issue. To reproduce this issue, download the bad image and the source Java code to the same directory and then run:

      java --add-exports java.desktop/com.sun.imageio.plugins.jpeg=ALL-UNNAMED ImageIOTest.java badimage.jpg

      (Please ignore the direct references to com.sun.imageio.plugins.jpeg.JPEGImageReader class and the related add-exports instruction. These are there just to simplify the reproducer)

      When that above command is run against Java 18 (or any earlier versions), you should see the following output:

      ======
      Trying to read badimage.jpg using reader com.sun.imageio.plugins.jpeg.JPEGImageReader
      Received the expected exception - javax.imageio.IIOException: Unsupported Image Type
      Success
      ======

      When run against Java 19 EA version:

      java -version
      openjdk version "19-ea" 2022-09-20
      OpenJDK Runtime Environment (build 19-ea+23-1706)
      OpenJDK 64-Bit Server VM (build 19-ea+23-1706, mixed mode, sharing)
      you'll see the following output/failure:

      =======
      Running test against badimage.jpg
      Trying to read badimage.jpg using reader com.sun.imageio.plugins.jpeg.JPEGImageReader
      Exception in thread "main" java.lang.RuntimeException: ImageReader.read did not throw an exception that was expected to be thrown
      at ImageIOTest.main(ImageIOTest.java:29)
      =======

      This failure was caught in one of the tests in Apache Ant project testsuite. The same badimage.jpg that is attached to this issue is available in the Ant project repo here https://github.com/apache/ant/blob/master/src/etc/testcases/taskdefs/optional/image/src/badimage.jpg

            prr Philip Race
            jpai Jaikiran Pai
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: