Bug 53432

Summary: workbook.getAllPictures() throws NullPointerException when called after adding an image to a workbook without images
Product: POI Reporter: Artem Karpenko <gooyozh>
Component: HSSFAssignee: POI Developers List <dev>
Status: VERIFIED FIXED    
Severity: normal    
Priority: P2    
Version: 3.9-dev   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Attachments: Test case, slightly modified snippet for adding an image from "quick guide".

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!