From: Yegor Kozlov Date: Tue, 29 May 2007 08:32:56 +0000 (+0000) Subject: fixed bug 38256: RuntimeException: Couldn't instantiate the class for type with id 0 X-Git-Tag: REL_3_0_1_RC1~13 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=3a7fba441c1563042ec37b5ac3ab847fd0b6d86b;p=poi.git 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 --- diff --git a/src/scratchpad/src/org/apache/poi/hslf/HSLFSlideShow.java b/src/scratchpad/src/org/apache/poi/hslf/HSLFSlideShow.java index 84a03e7a52..e41bc3d5d0 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/HSLFSlideShow.java +++ b/src/scratchpad/src/org/apache/poi/hslf/HSLFSlideShow.java @@ -219,11 +219,42 @@ 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; + } + /** * Find the "Current User" stream, and load it */ diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/data/38256.ppt b/src/scratchpad/testcases/org/apache/poi/hslf/data/38256.ppt new file mode 100644 index 0000000000..a0883bda00 Binary files /dev/null and b/src/scratchpad/testcases/org/apache/poi/hslf/data/38256.ppt differ diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java index 800194e585..cd1d9fd6b0 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java @@ -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 Scott’s B’Day… See you all there!"); + + for (int i = 0; i < runs.length; i++) { + String text = runs[i].getRawText(); + assertTrue(txt.contains(text)); + } + + } + }