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

ImageIO.write() method will throw IndexOutOfBoundsException

    XMLWordPrintable

    Details

      Description

      ADDITIONAL SYSTEM INFORMATION :
      Windows x64 19042.804 OpenJDK Runtime Environment AdoptOpenJDK (build 15.0.2+7)
      WSL Kail Linux OpenJDK Runtime Environment (build 11.0.10+9-post-Debian-1)

      A DESCRIPTION OF THE PROBLEM :
      With some specific images, ImageIO.write() method will throw IndexOutOfBoundsException which isn't declared to be thrown.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      My source code "MyChange.java" was pasted below.
      And I uploaded the input image to https://i.ibb.co/Js518Zx/image.png.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      throw IOException or declare this method maybe throw IndexOutOfBoundsException
      ACTUAL -
      Exception in thread "main" java.lang.IndexOutOfBoundsException
              at java.base/java.io.RandomAccessFile.writeBytes(Native Method)
              at java.base/java.io.RandomAccessFile.write(RandomAccessFile.java:561)
              at java.desktop/javax.imageio.stream.FileImageOutputStream.write(FileImageOutputStream.java:124)
              at java.desktop/com.sun.imageio.plugins.bmp.BMPImageWriter.write(BMPImageWriter.java:654)
              at java.desktop/javax.imageio.ImageWriter.write(ImageWriter.java:613)
              at java.desktop/javax.imageio.ImageIO.doWrite(ImageIO.java:1628)
              at java.desktop/javax.imageio.ImageIO.write(ImageIO.java:1554)
              at test.MyChange.main(MyChange.java:16)

      ---------- BEGIN SOURCE ----------

      package test;

      import java.awt.image.BufferedImage;
      import java.io.File;
      import java.io.FileInputStream;
      import java.io.IOException;
      import java.io.InputStream;

      import javax.imageio.ImageIO;

      public class MyChange {
          public static void main(String[] args) {
              File inputFile = new File("0.png");
              try (InputStream is = new FileInputStream(inputFile)) {
                  BufferedImage image = ImageIO.read(is);
                  ImageIO.write(image, "bmp", new File("0.bmp"));
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
      }

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

      FREQUENCY : always


        Attachments

        1. 0.png
          0.png
          2 kB
        2. MyChange.java
          0.6 kB

          Activity

            People

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

              Dates

              Created:
              Updated: