When header length more than 255 symbols (maximum allowed by xls format) java.lang.ArrayIndexOutOfBoundsException occures Code: HSSFWorkbook workBook = new HSSFWorkbook(); HSSFSheet sheet = workBook.createSheet("Sheet 1"); sheet.getHeader().setCenter(reportTitle); Exception: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException at java.lang.System.arraycopy(Native Method) at org.apache.poi.util.StringUtil.putUnicodeLE(StringUtil.java:208) at org.apache.poi.hssf.record.HeaderRecord.serialize(HeaderRecord.java:179) at org.apache.poi.hssf.model.Sheet.serialize(Sheet.java:825) at org.apache.poi.hssf.usermodel.HSSFWorkbook.getBytes(HSSFWorkbook.java:1188) at org.apache.poi.hssf.usermodel.HSSFWorkbook.write(HSSFWorkbook.java:1118) at poiutils.HSSFUtils.flushWorkBook(HSSFUtils.java:170) at POITest.main(POITest.java:45)
Any thoughts on what would be a logical exception to throw instead? Perhaps IllegalArgumentException or IllegalStateException I think picking the right exception may well be harder than detecting the situation and throwing it :)
IllegalArgumentException is now thrown at the right point
svn r697559 .
This bug was probably mis-diagnosed. Excel handles header / footer text longer than 256 bytes, and none of the documentation mentions this limit. Prior to the introduction of StandardRecord (and LittleEndian input/output refactoring of the BIFF serialization) this code was much more fragile. It's likely that the original bug was fixed through all that work. As of the fix for bug 47244, POI now allows header / footer text much longer than 256 bytes. POI enforces a limit of 8221 bytes. I am not sure if this is the absolute max, but it avoids the need for BIFF record continuation logic.