Bug 46575 - [PATCH]NullPointerException in HSSFWorkbook.convertLabelRecords
Summary: [PATCH]NullPointerException in HSSFWorkbook.convertLabelRecords
Status: RESOLVED DUPLICATE of bug 42570
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: unspecified
Hardware: PC Windows XP
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-01-21 03:54 UTC by Jürgen Wehren
Modified: 2009-01-29 16:24 UTC (History)
0 users



Attachments
Patch for NPX in HSSFWorkbook.convertLabelRecords() (653 bytes, patch)
2009-01-21 03:54 UTC, Jürgen Wehren
Details | Diff
Excel Sheet with an embedded Diagram/Chart that will cause the NPX (14.00 KB, application/vnd.ms-excel)
2009-01-21 03:56 UTC, Jürgen Wehren
Details

Note You need to log in before you can comment on or make changes to this bug.
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 ***