Bug 45686 - Multible calls of TextRun.changeTextInRichTextRun causes Exception
Summary: Multible calls of TextRun.changeTextInRichTextRun causes Exception
Status: RESOLVED WORKSFORME
Alias: None
Product: POI
Classification: Unclassified
Component: HSLF (show other bugs)
Version: 3.0-FINAL
Hardware: PC Windows XP
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-08-25 08:36 UTC by Thorsten
Modified: 2015-05-01 20:22 UTC (History)
0 users



Attachments
sample source code (745 bytes, text/plain)
2008-08-25 08:36 UTC, Thorsten
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Thorsten 2008-08-25 08:36:40 UTC
Created attachment 22479 [details]
sample source code

Hi,

 I try to update RichTextRun-Objects in a TextRun-Object.

When I call TextRun.changeTextInRichTextRun(RichTextRun[0],"") the first time everything works fine. But when I call it a second time TextRun.changeTextInRichTextRun(RichTextRun[1],"Hello") I get the following Exception:

Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 68
     at java.lang.String.substring(Unknown Source)
     at org.apache.poi.hslf.usermodel.RichTextRun.getRawText(RichTextRun.java:158)
     at org.apache.poi.hslf.model.TextRun.changeTextInRichTextRun(TextRun.java:435)
     at substitutionClassesForPptParser.SimpleSubstitution.handeSubstitution(SimpleSubstitution.java:99)
     at methodsFromPptParser.ProcessPptDocumet.importPlaceholder(ProcessPptDocumet.java:94)
     at Tester.main(Tester.java:16)


 I try something like that.

 RichTextRun[0] --> "Hello"
 RichTextRun[1] --> "World"
 RichTextRun[2] --> "POI"


 TextRun.changeTextInRichTextRun(RichTextRun[0], "");
 TextRun.changeTextInRichTextRun(RichTextRun[1], "Java");
 TextRun.changeTextInRichTextRun(RichTextRun[0], "Apache");


I have attached some sample source code
Comment 1 Dominik Stadler 2015-05-01 20:22:06 UTC
I quickly tried to reproduce this old bug report, but could not. Also the code that you posted is not self-sufficient, so it is hard to exactly run what you did back then. 

So I believe that this is fixed in the meantime and thus will close this as WORKSFORME for now. If this is still a problem for you then please reopen the bug together with a self-sufficient unit test and any sample files that are used in the test so we can reproduce the problem.