fixed bug 38256: RuntimeException: Couldn't instantiate the class for type with id 0

git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@542453 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yegor Kozlov 2007-05-29 08:32:56 +00:00
parent 28b2906621
commit aeaf8fe21f
3 changed files with 63 additions and 3 deletions

View File

@ -219,9 +219,40 @@ public class HSLFSlideShow extends POIDocument
// If you don't know about the type, play safe and skip over it (using
// its length to know where the next record will start)
//
// For now, this work is handled by Record.findChildRecords
_records = Record.findChildRecords(_docstream,0,_docstream.length);
_records = read(_docstream, (int)currentUser.getCurrentEditOffset());
}
private Record[] read(byte[] docstream, int usrOffset){
ArrayList lst = new ArrayList();
while (usrOffset != 0){
UserEditAtom usr = (UserEditAtom) Record.buildRecordAtOffset(docstream, usrOffset);
lst.add(new Integer(usrOffset));
int psrOffset = usr.getPersistPointersOffset();
PersistPtrHolder ptr = (PersistPtrHolder)Record.buildRecordAtOffset(docstream, psrOffset);
lst.add(new Integer(psrOffset));
Hashtable entries = ptr.getSlideLocationsLookup();
for (Iterator it = entries.keySet().iterator(); it.hasNext(); ) {
Integer id = (Integer)it.next();
Integer offset = (Integer)entries.get(id);
lst.add(offset);
}
usrOffset = usr.getLastUserEditAtomOffset();
}
//sort found records by offset.
//(it is not necessary but SlideShow.findMostRecentCoreRecords() expects them sorted)
Object a[] = lst.toArray();
Arrays.sort(a);
Record[] rec = new Record[lst.size()];
for (int i = 0; i < a.length; i++) {
Integer offset = (Integer)a[i];
rec[i] = (Record)Record.buildRecordAtOffset(docstream, offset.intValue());
}
return rec;
}
/**

View File

@ -269,4 +269,33 @@ public class TestBugs extends TestCase {
}
/**
* Bug 38256: RuntimeException: Couldn't instantiate the class for type with id 0.
* ( also fixed followup: getTextRuns() returns no text )
*/
public void test38256 () throws Exception {
FileInputStream is = new FileInputStream(new File(cwd, "38256.ppt"));
SlideShow ppt = new SlideShow(is);
is.close();
assertTrue("No Exceptions while reading file", true);
Slide[] slide = ppt.getSlides();
assertEquals(1, slide.length);
TextRun[] runs = slide[0].getTextRuns();
assertEquals(4, runs.length);
HashSet txt = new HashSet();
txt.add("“HAPPY BIRTHDAY SCOTT”");
txt.add("Have a HAPPY DAY");
txt.add("PS Nobody is allowed to hassle Scott TODAY…");
txt.add("Drinks will be in the Boardroom at 5pm today to celebrate Scotts BDay… See you all there!");
for (int i = 0; i < runs.length; i++) {
String text = runs[i].getRawText();
assertTrue(txt.contains(text));
}
}
}