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

IndexOutOfBoundsException when drawing PNGs

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 9
    • 6u20, 8, 9
    • client-libs
    • b100
    • x86
    • windows_xp

      FULL PRODUCT VERSION :
      java version "1.6.0_20"
      Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
      Java HotSpot(TM) Client VM (build 16.3-b01, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Windows XP SP3

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      n/a
      Used a ServletOutputStream, connected to localhost.

      A DESCRIPTION OF THE PROBLEM :
      When drawing PNG images to a ServletOutputStream using the following method:
                  javax.imageio.ImageIO.write(image, "png", outStream);

      I receive the following stack trace:

      java.lang.IndexOutOfBoundsException
      at javax.imageio.stream.FileCacheImageOutputStream.seek(FileCacheImageOutputStream.java:151)
      at javax.imageio.stream.FileCacheImageOutputStream.close(FileCacheImageOutputStream.java:212)
      at javax.imageio.ImageIO.write(ImageIO.java:1567)
      ... (our code)

      After some investigation, I've found that in javax.imageio.stream.FileCacheImageOutputStream.seek(), flushedPos is set to 4 bytes past the end of the cache file, which causes the exception when the stream is flushed since 'pos' is the actual end of the file, and is before the 'flushedPos'.

      This bug does not always happen. In 20 draws it would occur anywhere from 3-7 times. (It's a mapping application, and the draws are map tiles.)

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Create an OutputStream.
      2. Load a PNG file into memory.
      3. Use the javax.imageio.ImageIO.write method to write the image to the stream.



      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The image should draw, there should be no exception thrown, and the cache file should be deleted.
      ACTUAL -
      The image draws, but there is an exception thrown, and the cache file remains in the cache directory.

      REPRODUCIBILITY :
      This bug can be reproduced occasionally.

      CUSTOMER SUBMITTED WORKAROUND :
      Use a memory cache.

            jdv Jayathirth D V
            igor Igor Nekrestyanov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: