Bug 54392

Summary: HSSFWorkbook initialization fail, with RuntimeException during creation of HSSFSheet, caused by an unknown excel format
Product: POI Reporter: steveoreo
Component: HSSFAssignee: POI Developers List <dev>
Severity: normal    
Priority: P2    
Version: 3.9-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Attachments: the excel file to reproduce

Description steveoreo 2013-01-09 10:38:32 UTC
java version "1.6.0_31"
Java(TM) SE Runtime Environment (build 1.6.0_31-b05)
poi version: poi-3.9-20121203.jar
platform: windows xp 

------------ source to reproduce is very simple:
String s = "excelfile.xls";
FileInputStream fis = new FileInputStream(file);
workbook = new HSSFWorkbook (fis);

and then it would trigger this. 
it would be nice if it can be fixed. or at least with an extra constructor boolean to disable this check & throw. 

                    // Some tools (like Perl module Spreadsheet::WriteExcel - bug 41187) skip the RowRecords
                    // Excel, OpenOffice.org and GoogleDocs are all OK with this, so POI should be too.
                    if (rowRecordsAlreadyPresent) {
                        // if at least one row record is present, all should be present.
                        throw new RuntimeException("Unexpected missing row when some rows already present");

Since I am very eager to use poi for this excel file, I disabled this throw statement and the rest of the parising can run perfectly fine. 

------------ Exception:
Error initializing Excel File:Unexpected missing row when some rows already present
java.lang.RuntimeException: Unexpected missing row when some rows already present
        at org.apache.poi.hssf.usermodel.HSSFSheet.setPropertiesFromSheet(HSSFSheet.java:195)
        at org.apache.poi.hssf.usermodel.HSSFSheet.<init>(HSSFSheet.java:120)
        at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:292)
        at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:243)
        at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:187)
        at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:322)
        at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:303)
Comment 1 Nick Burch 2013-01-09 10:55:42 UTC
Where did the problematic file come from? If you try opening the file in excel and doing a save-as, does that fix it?
Comment 2 steveoreo 2013-01-09 13:57:05 UTC
Created attachment 29831 [details]
the excel file to reproduce
Comment 3 steveoreo 2013-01-09 13:58:45 UTC
The file is coming from internet web site. 
I grep it and try to use poi to parse. 
I attached in the bugzilla for your reference (sorry I missed it before). 
thanks for your prompt response!
Comment 4 Nick Burch 2014-07-24 16:09:23 UTC
I've just tried the attached file with 3.10 Final, and it opens without error
Comment 5 Triqui 2016-02-22 18:04:50 UTC
This looks like an exact duplicate of bug 47245 and bug 49312

Please, correct me if I'm wrong.
Comment 6 Triqui 2016-02-23 10:05:33 UTC
I've just tried the attached file with 3.10-FINAL, and the error is still there.
I've just tried the attached file with 3.13, and the error is still there.
I've just tried the attached file with 3.14-beta1, and the error is still there.

It's been several years now and the workaround suggested in the bug 47245 still works without side effects. Despite the comments in the source code suggesting to remove the exception altogether this bug still persists, and I can't really understand why.

It would be great if someone with more knowledge would take a little minute to explain why this exception has to be thrown.
Comment 7 Dominik Stadler 2016-02-23 13:36:07 UTC
There is still an open bug-report where further discussion of this should take place, so no need to have this open as well. It seems the origins of the code are somewhat lost in time, so the best chance of moving it along is probably to research why the code was built this way originally and comment in the open bug item.

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