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

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

XMLWordPrintable

    • b116
    • x86
    • windows_7

        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.

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

                Created:
                Updated:
                Resolved: