Bug 53432 - workbook.getAllPictures() throws NullPointerException when called after adding an image to a workbook without images
Summary: workbook.getAllPictures() throws NullPointerException when called after addin...
Status: VERIFIED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.9-dev
Hardware: PC Windows XP
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-06-18 08:28 UTC by Artem Karpenko
Modified: 2012-08-15 09:33 UTC (History)
0 users



Attachments
Test case, slightly modified snippet for adding an image from "quick guide". (1.80 KB, application/octet-stream)
2012-06-18 08:28 UTC, Artem Karpenko
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Artem Karpenko 2012-06-18 08:28:14 UTC
Created attachment 28953 [details]
Test case, slightly modified snippet for adding an image from "quick guide".

Attached is the code to reproduce exception. This is basically snippet from "Busy developers' guide" to add a picture except that saving workbook part is skipped, instead there is a call to wb.getAllPictures() which throws NullPointerException:

java.lang.NullPointerException
	at org.apache.poi.hssf.record.AbstractEscherHolderRecord.decode(AbstractEscherHolderRecord.java:261)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.getAllPictures(HSSFWorkbook.java:1639)
	at ExcelImageNpeTest.test(ExcelImageNpeTest.java:46)

This also happens if instead of creating a workbook you open existing one without any images inside, add image and call getAllPictures(). 
This does not happen when opening a workbook without images and calling getAllPictures() without adding an image. 
This does not happen when opening a workbook with images inside and adding a new one (but getAllPictures().size() will return previous number of images, i.e. will not take into account just added one).

Also happens with PNG images.
Does not happen with XSSF workbook.

Tested with 3.8 and build 20120613 from Jenkins.
Comment 1 Evgeniy Berlog 2012-08-15 09:07:27 UTC
This problem should be fixed in trunk.

Please try with a nightly build - see download links on http://poi.apache.org/
or build yourself from SVN trunk, see http://poi.apache.org/subversion.html
Comment 2 Artem Karpenko 2012-08-15 09:33:36 UTC
Build 3.9-beta1-20120815 works for me. Thanks!