Bug 51148 - XWPFDocument.removeBodyElement(int pos) error
Summary: XWPFDocument.removeBodyElement(int pos) error
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: XWPF (show other bugs)
Version: 3.7-FINAL
Hardware: PC Windows XP
: P2 major (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-05-04 09:40 UTC by ptorrodellas
Modified: 2011-05-06 02:14 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description ptorrodellas 2011-05-04 09:40:04 UTC
XWPFDocument.removeBodyElement(int pos) throws IndexOutOfBoundsException whatever the value of the element index.

I think that this is caused by two XWPFDocument class code errors:

1 - In removeBodyElement(int pos), the statement:

bodyElements.remove(pos);

should be placed AFTER the statements:

Integer tablePos = getTablePos(pos); 

and

Integer paraPos = getParagraphPos(pos);

instead of before, otherwise the element is not there in the bodyElements List to be used to locate it in the paragraphs or tables Lists.

2 - In getParagraphPos(int pos) and getTablePos(int pos), the for loop should be:
for(int i = startPos; i >= 0; i--) {
....
}
Comment 1 Nick Burch 2011-05-06 02:14:48 UTC
Good spot. I've cleaned up the code a bit (the table/paragraph code is now generic), and added a bunch of unit tests for it. Fixed in r1100027.