Bug 13076

Summary: [PATCH] NullPointerException in FormulaRecord
Product: POI Reporter: Dennis Doubleday <dennis>
Component: HSSFAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: normal CC: moj
Priority: P3    
Version: 2.0-dev   
Target Milestone: ---   
Hardware: PC   
OS: All   
Attachments: Excel document that caused the bug report
Patch file that fixes the problem

Description Dennis Doubleday 2002-09-27 14:01:24 UTC
The version is actually 1.8.0-dev, but I didn't see that in the list.

I got the following exception when running BiffViewer on the file attached to
this bug:

============================================
Offset 0x20db (8411)
[WARNING] Unknown Ptg 12 (18) at cell (10,1)
recordid = 0x6, size =30
java.lang.NullPointerException
        at org.apache.poi.hssf.record.FormulaRecord.toString(FormulaRecord.java:
548)
        at org.apache.poi.hssf.dev.BiffViewer.createRecord(BiffViewer.java:638)
        at org.apache.poi.hssf.dev.BiffViewer.createRecords(BiffViewer.java:158)

        at org.apache.poi.hssf.dev.BiffViewer.run(BiffViewer.java:110)
        at org.apache.poi.hssf.dev.BiffViewer.main(BiffViewer.java:687)
Comment 1 Dennis Doubleday 2002-09-27 14:03:14 UTC
Created attachment 3259 [details]
Excel document that caused the bug report
Comment 2 Dennis Doubleday 2002-11-11 22:06:56 UTC
I found what causes the NPE. In FormulaRecord.fillFields(), if an
UnsupportedOperationException is thrown while parsing, the field
field_8_parsed_expr is set to null, but then the following appears in
FormulaRecord.toString() (line 548):

buffer.append("    .numptgsinarray  = ").append(field_8_parsed_expr.size())
                .append("\n");
            
for (int k = 0; k < field_8_parsed_expr.size(); k++ ) {

Either reference to field_8_parsed_expr.size() will cause an NPE because the
field was set to null.
Comment 3 Dennis Doubleday 2002-11-12 16:45:37 UTC
Created attachment 3821 [details]
Patch file that fixes the problem
Comment 4 Dennis Doubleday 2002-11-12 16:46:01 UTC
Patch attached. Note that this patch means that BiffViewer will not fail with an
exception when a formula doesn't parse--you'll just see a WARNING in the output.
Maybe that means you want to change BiffViewer, but this is the right patch for
this problem, anyway.
Comment 5 Andy Oliver 2002-11-28 18:59:00 UTC
applied and committed.  Please crosscheck.  It would be good if we could signal
an error in a recoverable way.