Bug 19053 - same ".xls" file can't read - ClassCastException LabelRecord
Summary: same ".xls" file can't read - ClassCastException LabelRecord
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 2.0-FINAL
Hardware: Sun Solaris
: P3 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
: 28126 40460 (view as bug list)
Depends on:
Blocks:
 
Reported: 2003-04-16 06:42 UTC by Tang Wei
Modified: 2008-05-05 20:18 UTC (History)
2 users (show)



Attachments
Excel spreadsheet that causes java.lang.ClassCastException: org.apache.poi.hssf.record.LabelRecord (33.50 KB, application/octet-stream)
2004-04-01 15:20 UTC, Perry Tew
Details
Just another test worksheet. (35.50 KB, application/excel)
2004-04-05 08:17 UTC, Julio Madrid
Details
Patch by John Thorhauer (jthorhauer at phoenixcolor.com) (1.55 KB, patch)
2004-07-06 18:37 UTC, Avik Sengupta
Details | Diff
A fix based on John Thorhauer's patch. (5.41 KB, patch)
2005-03-13 08:55 UTC, Youval
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tang Wei 2003-04-16 06:42:11 UTC
when i try to open a excel file,throw this:

java.lang.ClassCastException: org.apache.poi.hssf.record.LabelRecord
	at java.util.TreeMap.compare(TreeMap.java:1081)
	at java.util.TreeMap.getEntry(TreeMap.java:341)
	at java.util.TreeMap.get(TreeMap.java:260)
	at 
org.apache.poi.hssf.record.aggregates.ValueRecordsAggregate.insertCell
(ValueRecordsAggregate.java:92)
	at org.apache.poi.hssf.record.aggregates.ValueRecordsAggregate.construct
(ValueRecordsAggregate.java:151)
	at org.apache.poi.hssf.model.Sheet.createSheet(Sheet.java:206)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.(HSSFWorkbook.java:149)

my code:
      String filename = "D:\\study\\testexcel\\testbook.xls";
      FileInputStream finStream = new FileInputStream(filename);
      POIFSFileSystem fs = new POIFSFileSystem(finStream);
      HSSFWorkbook wb = new HSSFWorkbook(fs);//now has a Exception
Comment 1 Avik Sengupta 2003-04-16 09:14:10 UTC
Interesting. Can you attach a simple sheet that displays this problem?
Comment 2 Andy Oliver 2003-07-24 16:12:21 UTC
information asked for but not provided
Comment 3 Perry Tew 2004-04-01 12:27:57 UTC
I can reproduce this error using the 2.5 final binary distribution.
Here is my stack trace.  I will also attach the file that is causing the error,
however Bugzilla keeps timing out on my during the file upload.

This error is strange, because my end user that created this file typcially
never has problems uploading the spreadsheet and all of the sudden the same
spreadsheet is broken.  It opens fine in MS Excel.

I wasn't sure if I should "Reopen" this bug or mark it as "Verified".  If I've
chosen the wrong thing, forgive me.  I'm not very familar with Bugzilla yet.

Thanks for your help!!  I really appreciate it.

Test Case:
package com.novartis.cibavision.websupport.excel;

import junit.framework.TestCase;
import java.io.*;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;

import java.net.URL;

public class TestClassCastException extends TestCase{

	public TestClassCastException( String name ){ super( name ); }

	public void testClassCastException_Bare() throws Exception{

		String testData =
"com/novartis/cibavision/websupport/excel/test_labelrecord_error.xls";
		URL xlsURL = this.getClass().getClassLoader().getResource( testData );
		HSSFWorkbook workbook = new HSSFWorkbook(new
BufferedInputStream(xlsURL.openStream()));
		HSSFSheet sheet = workbook.getSheet("Calls");
	}

}



Stack Trace:
Testsuite: com.novartis.cibavision.websupport.excel.TestClassCastException
Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 1.259 sec

Testcase: testClassCastException_Bare took 1.25 sec
        Caused an ERROR
org.apache.poi.hssf.record.LabelRecord
java.lang.ClassCastException: org.apache.poi.hssf.record.LabelRecord
        at java.util.TreeMap.compare(TreeMap.java:1047)
        at java.util.TreeMap.put(TreeMap.java:449)
        at
org.apache.poi.hssf.record.aggregates.ValueRecordsAggregate.insertCell(ValueRecordsAggregate.java:65)
        at
org.apache.poi.hssf.record.aggregates.ValueRecordsAggregate.construct(ValueRecordsAggregate.java:130)
        at org.apache.poi.hssf.model.Sheet.createSheet(Sheet.java:192)
        at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:174)
        at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:212)
        at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:193)
        at
com.novartis.cibavision.websupport.excel.TestClassCastException.testClassCastException_Bare(Unknown
Source)





Comment 4 Perry Tew 2004-04-01 12:34:29 UTC
I still cannot get the file upload to work.  Is there anyone I can E-mail the
excel sheet to that can then upload it into Bugzilla?  It's probably the
filewall I'm behind or something.

Thanks!
Perry Tew
Comment 5 Perry Tew 2004-04-01 15:20:49 UTC
Created attachment 11082 [details]
Excel spreadsheet that causes java.lang.ClassCastException: org.apache.poi.hssf.record.LabelRecord
Comment 6 Perry Tew 2004-04-01 15:21:42 UTC
I found a small spreadsheet (less than 10 lines) that is causing the same error.
 Avik, you're right.  It was the size of the file that will preventing the upload.

Comment 7 Avik Sengupta 2004-04-02 12:05:22 UTC
*** Bug 28126 has been marked as a duplicate of this bug. ***
Comment 8 Julio Madrid 2004-04-05 08:17:34 UTC
Created attachment 11132 [details]
Just another test worksheet.
Comment 9 Julio Madrid 2004-04-05 08:39:37 UTC
Well, Speaking about side effects, I can find that convert Label Records 
increases number of records in woorkbook due to sst table. So you must set the 
initial record offset prior to convert the Label Records. Otherwise, the 
application could fall into an infinite loop due to the lost of BOF Records.
Comment 10 Avik Sengupta 2004-07-01 07:42:31 UTC
For the record, the files attached by Perry Tew fail to open since they are
saved by Pocket Excel on an iPAQ. Apparently, Pocket Excel saves in Excel95
format, while POI of course handles Excel97+. Workaround is to re-save the file
in desktop excel. 

Havent looked at the attachement filed by Julio Madrid, so dunno if it is the
same problem. Will find out..
Comment 11 Avik Sengupta 2004-07-01 07:44:47 UTC
Sorry.. even Julio's file is, of course, created on an handheld. see duplicate
bug 28126 for details. 
Comment 12 Avik Sengupta 2004-07-06 18:37:42 UTC
Created attachment 12043 [details]
Patch by  John Thorhauer (jthorhauer at phoenixcolor.com)
Comment 13 Jason Height 2004-10-14 22:17:11 UTC
Err should this patch be applied or not?

Jason
Comment 14 Danny Mui 2004-10-15 22:21:56 UTC
does your recent SST fix address this (very cool btw)?  saw that mentioned
somewhere :)
Comment 15 Jason Height 2004-10-17 22:23:19 UTC
Nope. Had a look at the patch and the idea seems reasonable, although i will
probably change how it works slightly.

Does anyone recall why this patch, which basically takes a LabelRecord and
converts it to a LabelSSTRecord, was no applied??? Otherwise i think that i will
apply it.
Comment 16 Jason Height 2004-10-18 04:19:22 UTC
Ok had a bit more of a look and the patch was applied. Its just that it doesnt
now work.

Will work on it.
Comment 17 Youval 2005-03-13 08:55:43 UTC
Created attachment 14475 [details]
A fix based on John Thorhauer's patch.

I've tested it on the 2 spreadsheets previously attached and have been using a
version that includes this patch for several months now, so (at least for my
uses), it seems to be correct. Still, someone with *real* knowledge of HSSF
should probably look at it before comitting ...
Comment 18 Jason Height 2005-08-26 05:41:01 UTC
Patch applied to CVS.
Comment 19 Josh Micich 2008-05-05 20:18:32 UTC
*** Bug 40460 has been marked as a duplicate of this bug. ***