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

JPEGReader.readAll() throws NPE when thumbnails are present in the input source

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b36
    • CPU:
      generic, x86
    • OS:
      generic, linux

      Description

      The Specification for ImageReader.readAll() claims that this method will read the images as well as thumbnails present in the input source. But when the input source contains some thumbnails, this method throws NullPointerException for JPEG ImageReader. When I looked into the code of ImageReader.readAll(), this method appends the thumbnails to a null List. Here is the code snippet from ImageReader class: (starts from line no: 1048)

      List thumbnails = null;
      int numThumbnails = getNumThumbnails(imageIndex);
      for (int j = 0; j < numThumbnails; j++) {
          thumbnails.add(readThumbnail(imageIndex, j));
      }
       
      When you look at this code, it is very obvious that the thumbnails list is not instantiated and still remains as null when it is used inside the 'for' loop. Hence NPE is thrown.

      This is reproducible right from JDK1.4 on all the platforms.

      I have attached a sample code which would write some thumbnails to the file and will try to read the same using ImageReader. If you see the null pointer exception on the console, the bug is reproduced.
      ---------------------------------------------------------------------------

      I have noticed that the same code is repeated under readAll(Iterator) method also. That must also be fixed. To be specific, line no: 1164 to 1168.

      ###@###.### 2003-11-22

        Attachments

          Activity

            People

            Assignee:
            pmohansunw Praveen Mohan (Inactive)
            Reporter:
            pmohansunw Praveen Mohan (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: