Uploaded image for project: 'Commons Imaging'
  1. Commons Imaging
  2. IMAGING-48

JpegImageMetadata getEXIFThumbnail may raise a null pointer exception

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 0.97
    • 1.0-alpha1
    • None
    • None

    Description

      A patch has been done to read thumbnail from exif metada (see bug 38). But there is a bug if exif is null (NullpointerException):

      public BufferedImage getEXIFThumbnail() throws ImageReadException, 
                              IOException { 
                      ArrayList dirs = exif.getDirectories(); 
                      for (int i = 0; i < dirs.size(); i++) { 
                              TiffImageMetadata.Directory dir = (TiffImageMetadata.Directory) dirs 
                                              .get(i); 
                              // Debug.debug("dir", dir); 
                              BufferedImage image = dir.getThumbnail(); 
                              if (null != image) 
                                      return image; 
                              JpegImageData jpegImageData = dir.getJpegImageData(); 
                              if(jpegImageData!=null){ 
                                  ByteArrayInputStream input = new ByteArrayInputStream(jpegImageData.data); 
                                  image = ImageIO.read(input); 
                                  if (image!=null) 
                                      return image; 
                              } 
                      } 
      
                      return null; 
              } 
      

      This patch correct the bug:

              if (exif!= null) {
                  ArrayList dirs = exif.getDirectories();
                  for (int i = 0; i < dirs.size(); i++) {
                      TiffImageMetadata.Directory dir = (TiffImageMetadata.Directory) dirs.get(i);
                      // Debug.debug("dir", dir);
                      BufferedImage image = dir.getThumbnail();
                      if (null != image) {
                          return image;
                      }
                      JpegImageData jpegImageData = dir.getJpegImageData();
                      if (jpegImageData != null) {
                          ByteArrayInputStream input = new ByteArrayInputStream(jpegImageData.data);
                          image = ImageIO.read(input);
                          if (image != null) {
                              return image;
                          }
                      }
                  }
              }
              return null;
      

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              alainmailing Alain
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: