Bug 51703 - IllegalArgumentException when applying font
Summary: IllegalArgumentException when applying font
Status: RESOLVED WORKSFORME
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.8-dev
Hardware: PC Linux
: P2 major (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-08-22 13:02 UTC by Jan
Modified: 2015-05-31 21:55 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jan 2011-08-22 13:02:08 UTC
I have seen POI failing to read several spreadsheets, with the following stack trace:

Caused by: java.lang.IllegalArgumentException: Start index must be less than end index.
at org.apache.poi.hssf.usermodel.HSSFRichTextString.applyFont(HSSFRichTextString.java:139)
at org.apache.poi.hssf.record.TextObjectRecord.processFontRuns(TextObjectRecord.java:157)
at org.apache.poi.hssf.record.TextObjectRecord.<init>(TextObjectRecord.java:133)
at sun.reflect.GeneratedConstructorAccessor45.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.apache.poi.hssf.record.RecordFactory$ReflectionConstructorRecordCreator.create(RecordFactory.java:57)
... 20 more 

Debugging it, it looks like there's a text record which has a font applied, where the length of the text string is 42 characters (in one of the examples), but the index for where to apply the font is 60.  The cases I've seen this being a problem all seem related to a floating graphic containing a formatted string only, but I don't know if that's definitely the cause of it as I haven't been able to reproduce this in a simple spreadsheet that I've created myself.

I'm afraid the spreadsheets I have that produce this problem can't be provided as they contain confidential data.
Comment 1 Nick Burch 2011-08-22 16:41:35 UTC
Can you try running the Microsoft Binary File Format validator tool against one of your problematic files, and see if that declares them to be spec-valid or not?
Comment 2 Jan 2011-08-26 08:43:43 UTC
I tried the Microsoft validator program as suggested, and these spreadsheets all fail with a message referring to the "DSF" record (http://msdn.microsoft.com/en-us/library/638F5C45-2742-4681-9304-C9E2E46A52A9).  So I guess that POI is not to blame?
Comment 3 Nick Burch 2011-08-26 09:26:33 UTC
(In reply to comment #2)
> I tried the Microsoft validator program as suggested, and these spreadsheets
> all fail with a message referring to the "DSF" record

Without the files we can't say for certain, but hat would certainly seem to indicate that the file wasn't produced by office, and instead by a third party program which doesn't follow the spec.
Comment 4 Dominik Stadler 2015-05-31 21:55:41 UTC
Discussion indicates that the problem is outside of POI here, therefore I am closing this as WORKSFORME for now.