If the length of a HSSFRichTextString object is > 32767, then a call to the length() method returns a negative value = 32767 - length. Though this isn't a big deal if it's expected behavior, it would be great to either change the method or update the Javadocs to specify this behavior.
Almost certainly a short vs int issue Can you please upload a file that triggers this, so we have something to hand to write a unit test against?
Created attachment 23006 [details] Contains string that exceeds max length of Excel cell. The attached file contains the String that when loaded into an HSSFRichTextString causes the length() method to return a negative number.
Uploaded an attachment containing a String longer than 32767 to assist in testing.
The attached file appears to be plain text, and not an excel file :( Any chance you could check your attachment, and re-upload?
Actually, I found the bug when I was creating an Excel file from an XML file, from which this plain text was extracted. The logic that lead to the discovery was reading the text from the XML file, creating an HSSFRichTextString object with the text, and then checking the length of that HSSFRichTextString before calling HSSFCell.setCellValue() to ensure it didn't exceed our max allowable length for a cell. Apologies for not being more clear in my original description.
Fixed in svn trunk, r724848