Bug 46575

Summary: [PATCH]NullPointerException in HSSFWorkbook.convertLabelRecords
Product: POI Reporter: Jürgen Wehren <juergen.wehren>
Component: HSSFAssignee: POI Developers List <dev>
Status: RESOLVED DUPLICATE    
Severity: normal    
Priority: P2    
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Attachments: Patch for NPX in HSSFWorkbook.convertLabelRecords()
Excel Sheet with an embedded Diagram/Chart that will cause the NPX

Description Jürgen Wehren 2009-01-21 03:54:24 UTC
Created attachment 23147 [details]
Patch for NPX in HSSFWorkbook.convertLabelRecords()

When reading an Excel Sheet with an embedded Excel Diagram a Nullpointer Exception occurs at HSSFWorkbook.convertLabelRecords:

Caused by: java.lang.NullPointerException
	at org.apache.poi.hssf.record.UnicodeString.setString(UnicodeString.java:343)
	at org.apache.poi.hssf.record.UnicodeString.<init>(UnicodeString.java:104)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.convertLabelRecords(HSSFWorkbook.java:303)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:215)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:259)
	at com.framesoft.ffr.dms.lucene.documentHandler.ExcelPoiHSSFHandler.getDocumentContent(ExcelPoiHSSFHandler.java:25)
	... 1 more

I fixed this issue for our project where we extract the text from multiple Excel Documents by changing this Line:

workbook.addSSTString(new UnicodeString(oldrec.getValue()));

with this Line:

workbook.addSSTString((oldrec.getValue() == null ? null : new UnicodeString(oldrec.getValue())));

I don't know if this is a valid solution for this issue but for us it fixed the problem. 

Maybe there is a problem with some of the ExcelSheets we are trying to read that have a LabelRecord with a Null value. The Nullpointer did not occur if one of the embedded ExcelDiagrams was removed. The Diagram is referencing a Table with an empty row, so maybe that is the reason for the problem. 

I attached an example for this diagram that will result in an NPX.
Comment 1 Jürgen Wehren 2009-01-21 03:56:27 UTC
Created attachment 23148 [details]
Excel Sheet with an embedded Diagram/Chart that will cause the NPX
Comment 2 Josh Micich 2009-01-29 16:24:39 UTC
The patch is specified to be applied against latest svn trunk, but the bug is no longer visible there.  The stacktrace provided is from an old version of POI.  The problem was fixed with bug 42570 (from version 3.1-beta2 onwards).

Please do a search first to save time in future. e.g.:
http://www.google.com/search?q=NullPointerException+convertLabelRecords

*** This bug has been marked as a duplicate of bug 42570 ***