While attempting to read a workbook with skeletal test program, I encountered the following exception: java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 191 at java.util.Vector.get(Vector.java:716) at org.apache.poi.hssf.usermodel.HSSFDataFormat.getBuiltinFormat (HSSFDataFormat.java:320) ... The portion of my code which lead up to this was inside a double loop over each row, and each cell in the row: HSSFCellStyle style = cell.getCellStyle(); short format = style.getDataFormat(); String formatString = HSSFDataFormat.getBuiltinFormat(format); The way I read the documentation, the HSSFDataFormat.getBuiltinFormat call should return a format String if one exists, or null. In this case, however, neither happened. Instead, I got an ArrayIndexOutOfBoundsException. Unless I've missed something, I suspect either the documentation should be updated or the code altered. For now, I'm going to attempt to work around this by checking the format index against HSSFDataFormat.getNumberOfBuiltinBuiltinFormats.
It will be much easier to fix if you could possibly supply a small worksheet and a test program that replicates this error.
Cant fix without excel file or better example. Sorry. Jason
I know longer have my original file, but looking at the 2.0 source, the problem is easy to see: (HSSFDataFormat.java) 308 /** 309 * get the format string that matches the given format index 310 * @param index of a built in format 311 * @return string represented at index of format or null if there is not a builtin format at that index 313 */ 314 public static String getBuiltinFormat( short index ) 315 { 316 if ( builtinFormats == null ) 317 { 318 populateBuiltinFormats(); 319 } 320 return (String) builtinFormats.get( index ); 321 } The JavaDoc clearly states that a String will be returned, or if one doesn't exist at that index, null will be returned. The implementation, however, has no guard to make sure its a valid index. All that has to be done is to check to see if index is less than the size of the list before calling get(index). If the index is greater-than-or-equal-to the size of the list, then null should be returned. There is a chance that I'm misunderstanding the intent of this method from the JavaDoc. If that is the case, I suggest the JavaDoc be changed to clarify that it is possible for this method to throw an exception (instead of returning null) when a bad index is given.
Ahh ok so it is a documentation type issue. Quite obvious when pointed out. Indicated possible exception in javadoc. Jason