Bug 45269 - but at replaceText function - String index out of range: -5
Summary: but at replaceText function - String index out of range: -5
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: HWPF (show other bugs)
Version: unspecified
Hardware: PC Windows XP
: P2 critical (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-06-24 07:39 UTC by Fabio Ebner
Modified: 2010-06-04 13:20 UTC (History)
2 users (show)



Attachments
.java and .doc file (3.98 KB, application/zip)
2008-06-24 07:39 UTC, Fabio Ebner
Details
Patch to this bug (3.09 KB, patch)
2009-04-01 06:16 UTC, Piotr Gawron
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Fabio Ebner 2008-06-24 07:39:09 UTC
Created attachment 22168 [details]
.java and .doc file

when i try to replace some text, sometimes the funciont dont got the all text in paragraph, i do one loop to got all text in paragraph but i got that error:

 at java.lang.StringBuffer.substring(StringBuffer.java:416)
Paragraph Text: 14as
offset - > -1
X = 14
String index out of range: -5
+ + + + + Word Dokument bearbeitet + + + + +
        at org.apache.poi.hwpf.usermodel.Range.text(Range.java:270)
        at org.apache.poi.hwpf.usermodel.HWPF.work(HWPF.java:84)
        at org.apache.poi.hwpf.usermodel.HWPF.<init>(HWPF.java:25)
        at testeword.Main.main(Main.java:51)



look at line Paragraph Text: 14as when te all text are 14asdasd  and other bug..


when i have some big text that continue in another line, she got like another paragraph but is not, because i dont press ENTER the line end and continue at line down


sorry my english
Comment 1 Piotr Gawron 2009-04-01 06:16:20 UTC
Created attachment 23433 [details]
Patch to this bug

Changes:
scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java
now the modification of size of Range during text replacement is changed recursively to upper levels

scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestProblems.java
test case to this bug was added

scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeReplacement.java
there was one error in this test case - after replacing text with new, longer text number of paragraphs in section changed (5->4), but it shouldn't

This patch need also the *.doc file which was attached before as
scratchpad\testcases\org\apache\poi\hwpf\data\Bug45269.doc
Comment 2 Nick Burch 2010-06-04 13:20:02 UTC
Thanks for this patch. Applied with slight tweaks in r951498.