commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alain (JIRA)" <j...@apache.org>
Subject [jira] Created: (SANSELAN-44) JpegImageMetadata getEXIFThumbnail may raise a null pointer exception
Date Tue, 21 Sep 2010 14:07:34 GMT
JpegImageMetadata getEXIFThumbnail may raise a null pointer exception
---------------------------------------------------------------------

                 Key: SANSELAN-44
                 URL: https://issues.apache.org/jira/browse/SANSELAN-44
             Project: Commons Sanselan
          Issue Type: Bug
    Affects Versions: 0.94-incubator
            Reporter: Alain
             Fix For: 0.94-incubator


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

<code>
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; 
        } 
</code>

This patch correct the bug:

<code>
TiffImageMetadata exifs = jpegMetadata.getExif();
        if (exifs != null) {
            ArrayList dirs = exifs.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;
</code>

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message