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

In ImageIO.write() and ImageIO.read() null stream is not handled properly.

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b116
    • CPU:
      x86
    • OS:
      windows_7

      Backports

        Description

        FULL PRODUCT VERSION :
        java version "1.7.0_25"
        Java(TM) SE Runtime Environment (build 1.7.0_25-b17)
        Java HotSpot(TM) Client VM (build 23.25-b01, mixed mode, sharing)

        ADDITIONAL OS VERSION INFORMATION :
        Microsoft Windows [Version 6.1.7601]

        A DESCRIPTION OF THE PROBLEM :
        In the ImageIO method
        "write(RenderedImage im, String formatName, File output) throws IOException"
        ImageOutputStream is created through code
        "stream = createImageOutputStream(output);"

        In the finally block stream is closed without null check
        "finally { stream.close(); }"
        But in the createImageOutputStream method there is a code like
        "try {
        iter = theRegistry.getServiceProvidersImageOutputStreamSpi.class,true);
         } catch (IllegalArgumentException e) { return null; } "

        so the catch block returns null which will make "stream=null" in the "write" method mentioned above.

        This will throw NullPointerException in the stream.close() call.

        Please put a null check in the finally block
        "if(stream!= null) stream.close();"

        Not just this specific write method on other write() and read() methods also we are not handling NPE properly.
        REPRODUCIBILITY :
        This bug can be reproduced occasionally.

          Attachments

            Issue Links

              Activity

                People

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

                  Dates

                  Created:
                  Updated:
                  Resolved: