Bug 45038

Summary: Unable to construct record instance (HSSFWorkbook)
Product: POI Reporter: lpechereau <pechereau_l>
Component: HSSFAssignee: POI Developers List <dev>
Severity: normal    
Priority: P2    
Version: 3.0-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   

Description lpechereau 2008-05-19 08:06:41 UTC

with the version 3.0.1 of POI I can do this code : 
is = new FileInputStream(myExcelFile);
POIFSFileSystem poifsFileSystem = new POIFSFileSystem(is);
HSSFWorkbook wb = new HSSFWorkbook(poifsFileSystem, false);

However, when I want to use the version 3.0.2 of POI (for use the Class "HSSFFormulaEvaluator"), it's impossible : 
HSSFWorkbook wb = new HSSFWorkbook(poifsFileSystem, false);  // Exception with 3.0.2 (and 2.5.1), no probleme with 3.0.1

The Exception is : 
org.apache.poi.hssf.record.RecordFormatException: Unable to construct record instance
	at org.apache.poi.hssf.record.RecordFactory.createRecord(RecordFactory.java:199)
	at org.apache.poi.hssf.record.RecordFactory.createRecords(RecordFactory.java:117)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:207)
	at business.extractfees.Go.doTreatmentByExcelFile(Go.java:298)
	at business.extractfees.Go.extractDataFromRepertoryGeneral(Go.java:205)
	at business.extractfees.Go.doTreatment(Go.java:87)
	at business.extractfees.Go.main(Go.java:67)
Caused by: java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
	at org.apache.poi.hssf.record.RecordFactory.createRecord(RecordFactory.java:187)
	... 6 more
Caused by: java.lang.UnsupportedOperationException:  Unknown Ptg in Formula: 0x2 (2)
	at org.apache.poi.hssf.record.formula.Ptg.createPtg(Ptg.java:357)
	at org.apache.poi.hssf.record.DVRecord.fillFields(DVRecord.java:201)
	at org.apache.poi.hssf.record.Record.<init>(Record.java:55)
	at org.apache.poi.hssf.record.DVRecord.<init>(DVRecord.java:134)
	... 11 more

I use for POI 3.0.1 : 
3.0.1 : 

and for POI 3.0.2 : 

NB : the file that I open is not on my station, but on the network; and the file is open ONLY for reading (protected by password if you want to write). 

So, is it normal that I can open the file with the version 3.0.1, but not with 3.0.2 ? 
Is it possible to try to evaluate a Formula with POI 3.0.1 ? 

Comment 1 Josh Micich 2008-05-19 08:34:24 UTC
Between versions 3.0.1 and 3.0.2 support for data validation was added. Before then, DVRecord and DVALRecord were uninterpreted by POI so the formulas contained within were uninterpreted too.

There are many possible explanations for why POI has failed in this way.  The only way to know for sure would be for you to upload an example of the offending spreadsheet.

It's possible that the formula truly does contain Ptg 0x02 (=tTbl), in which case this bug is the same as bug 44958.  It's also possible that there is some other bug that causes POI to get out of alignment while reading the token data. Many bugs have been fixed since 3.0.2 (for example bug 44710) so it might be worth trying out 3.1-beta1.  Even more recently bug 44306 (which could have symptoms like this) was fixed. it might be worth trying out the latest svn trunk.
Comment 2 David Fisher 2009-02-18 12:32:06 UTC
I am going to resolve this as FIXED - judging from Josh's comments. Without a response from the OP this is the best we can do.