Merged revisions 613395-613401 via svnmerge from

https://svn.apache.org/repos/asf/poi/trunk

........
  r613395 | yegor | 2008-01-19 15:27:02 +0100 (Sat, 19 Jan 2008) | 1 line
  
  use JDK 1.4 compatible constructor for IllegalStateException
........
  r613396 | yegor | 2008-01-19 15:28:10 +0100 (Sat, 19 Jan 2008) | 1 line
  
  add a check to prevent NPE in HSSFSheet.autoSizeColumn(). See Bug 44246
........
  r613400 | yegor | 2008-01-19 15:44:07 +0100 (Sat, 19 Jan 2008) | 1 line
  
  added unit tests for closed Bug 37684: Unhandled Continue Record Error
........
  r613401 | yegor | 2008-01-19 15:54:06 +0100 (Sat, 19 Jan 2008) | 1 line
  
  added a unit test for fixed bug 41139: Constructing HSSFWorkbook is failed,threw threw ArrayIndexOutOfBoundsException for creating UnknownRecord
........


git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@613822 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Ugo Cei 2008-01-21 09:56:56 +00:00
parent a0a4d90dfa
commit e421eadd57
7 changed files with 91 additions and 96 deletions

View File

@ -187,10 +187,13 @@ public class DVRecord extends Record
this.field_not_used_2 = in.readShort(); this.field_not_used_2 = in.readShort();
//read sec formula data condition //read sec formula data condition
// Not sure if this was needed or not... //Not sure if this was needed or not...
try { try {
in.skip(this.field_size_sec_formula); in.skip(this.field_size_sec_formula);
} catch(IOException e) { throw new IllegalStateException(e); } } catch(IOException e) {
e.printStackTrace();
throw new IllegalStateException(e.getMessage());
}
token_pos = 0; token_pos = 0;
while (token_pos < this.field_size_sec_formula) while (token_pos < this.field_size_sec_formula)

View File

@ -1748,7 +1748,7 @@ public class HSSFSheet
} else if (cell.getCellType() == HSSFCell.CELL_TYPE_BOOLEAN) { } else if (cell.getCellType() == HSSFCell.CELL_TYPE_BOOLEAN) {
sval = String.valueOf(cell.getBooleanCellValue()); sval = String.valueOf(cell.getBooleanCellValue());
} }
if(sval != null) {
String txt = sval + defaultChar; String txt = sval + defaultChar;
str = new AttributedString(txt); str = new AttributedString(txt);
copyAttributes(font, str, 0, txt.length()); copyAttributes(font, str, 0, txt.length());
@ -1771,6 +1771,7 @@ public class HSSFSheet
width = Math.max(width, layout.getBounds().getWidth() / defaultCharWidth); width = Math.max(width, layout.getBounds().getWidth() / defaultCharWidth);
} }
} }
}
if (width != -1) { if (width != -1) {
if (width > Short.MAX_VALUE) { //width can be bigger that Short.MAX_VALUE! if (width > Short.MAX_VALUE) { //width can be bigger that Short.MAX_VALUE!

Binary file not shown.

Binary file not shown.

View File

@ -954,6 +954,63 @@ extends TestCase {
assertTrue("No Exceptions while reading file", true); assertTrue("No Exceptions while reading file", true);
} }
/**
* Bug 37684 : Unhandled Continue Record Error
*/
public void test37684 () throws Exception {
FileInputStream in = new FileInputStream(new File(cwd, "37684-1.xls"));
HSSFWorkbook wb = new HSSFWorkbook(in);
in.close();
assertTrue("No exceptions while reading workbook", true);
//serialize and read again
ByteArrayOutputStream out = new ByteArrayOutputStream();
wb.write(out);
out.close();
assertTrue("No exceptions while saving workbook", true);
wb = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
assertTrue("No exceptions while reading saved stream", true);
in = new FileInputStream(new File(cwd, "37684-2.xls"));
wb = new HSSFWorkbook(in);
in.close();
assertTrue("No exceptions while reading workbook", true);
//serialize and read again
out = new ByteArrayOutputStream();
wb.write(out);
out.close();
assertTrue("No exceptions while saving workbook", true);
wb = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
assertTrue("No exceptions while reading saved stream", true);
}
/**
* Bug 41139: Constructing HSSFWorkbook is failed,threw threw ArrayIndexOutOfBoundsException for creating UnknownRecord
*/
public void test41139() throws Exception {
FileInputStream in = new FileInputStream(new File(cwd, "41139.xls"));
HSSFWorkbook wb = new HSSFWorkbook(in);
in.close();
assertTrue("No Exceptions while reading file", true);
//serialize and read again
ByteArrayOutputStream out = new ByteArrayOutputStream();
wb.write(out);
out.close();
wb = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
assertTrue("No Exceptions while reading file", true);
}
} }

View File

@ -44,72 +44,6 @@ public class TestUnfixedBugs extends TestCase {
protected String cwd = System.getProperty("HSSF.testdata.path"); protected String cwd = System.getProperty("HSSF.testdata.path");
/* ArrayIndexOutOfBound in BOFRecord */
public void test28772() throws java.io.IOException {
String filename = System.getProperty("HSSF.testdata.path");
filename=filename+"/28772.xls";
FileInputStream in = new FileInputStream(filename);
HSSFWorkbook wb = new HSSFWorkbook(in);
assertTrue("Read book fine!" , true);
}
/**
* Bug 37684: Unhandled Continue Record Error
*
* BUT NOW(Jan07): It triggers bug 41026!!
*
* java.lang.ArrayIndexOutOfBoundsException: 30
at org.apache.poi.hssf.record.aggregates.ValueRecordsAggregate.rowHasCells(ValueRecordsAggregate.java:219)
*/
public void test37684() throws Exception {
FileInputStream in = new FileInputStream(new File(cwd, "37684.xls"));
HSSFWorkbook wb = new HSSFWorkbook(in);
in.close();
HSSFSheet sheet = wb.getSheetAt( 0 );
assertNotNull(sheet);
assertTrue("No Exceptions while reading file", true);
//serialize and read again
ByteArrayOutputStream out = new ByteArrayOutputStream();
wb.write(out);
out.close();
wb = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
assertTrue("No Exceptions while reading file", true);
}
/**
* Bug 41139: Constructing HSSFWorkbook is failed,threw threw ArrayIndexOutOfBoundsException for creating UnknownRecord
*
* BUT NOW (Jan07): It throws the following in write!!
* java.lang.RuntimeException: Coding Error: This method should never be called. This ptg should be converted
at org.apache.poi.hssf.record.formula.AreaNPtg.writeBytes(AreaNPtg.java:54)
at org.apache.poi.hssf.record.formula.Ptg.serializePtgStack(Ptg.java:384)
at org.apache.poi.hssf.record.NameRecord.serialize(NameRecord.java:544)
at org.apache.poi.hssf.model.Workbook.serialize(Workbook.java:757)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.getBytes(HSSFWorkbook.java:952)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.write(HSSFWorkbook.java:898)
*/
public void test41139() throws Exception {
FileInputStream in = new FileInputStream(new File(cwd, "41139.xls"));
HSSFWorkbook wb = new HSSFWorkbook(in);
in.close();
assertTrue("No Exceptions while reading file", true);
//serialize and read again
ByteArrayOutputStream out = new ByteArrayOutputStream();
wb.write(out);
out.close();
wb = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
assertTrue("No Exceptions while reading file", true);
}
public void test43493() throws Exception { public void test43493() throws Exception {
// Has crazy corrup subrecords on // Has crazy corrup subrecords on