https://bz.apache.org/bugzilla/show_bug.cgi?id=65916
Bug ID: 65916
Summary: IndexOutOfBoundsException - Workbook.write()
Product: POI
Version: 5.2.0-FINAL
Hardware: PC
OS: Mac OS X 10.1
Status: NEW
Severity: normal
Priority: P2
Component: XSSF
Assignee: [email protected]
Reporter: [email protected]
Target Milestone: ---
Created attachment 38213
--> https://bz.apache.org/bugzilla/attachment.cgi?id=38213&action=edit
`_firstChild`, _nextSibling...
=========================
Where you are throwing an exception
=========================
org.apache.xmlbeans.impl.store.Xobj
private static void removeElement(Xobj x) {
if (x == null) {
throw new IndexOutOfBoundsException();
}
...
=========================
Stack trace
=========================
java.lang.IndexOutOfBoundsException
at org.apache.xmlbeans.impl.store.Xobj.removeElement(Xobj.java:2099)
at org.apache.xmlbeans.impl.store.Xobj.remove_element(Xobj.java:2130)
at
org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTRowImpl.removeC(CTRowImpl.java:145)
at org.apache.poi.xssf.usermodel.XSSFRow.fixupCTCells(XSSFRow.java:612)
at
org.apache.poi.xssf.usermodel.XSSFRow.onDocumentWrite(XSSFRow.java:581)
at org.apache.poi.xssf.usermodel.XSSFSheet.write(XSSFSheet.java:3671)
at org.apache.poi.xssf.usermodel.XSSFSheet.commit(XSSFSheet.java:3616)
at
org.apache.poi.ooxml.POIXMLDocumentPart.onSave(POIXMLDocumentPart.java:467)
at
org.apache.poi.ooxml.POIXMLDocumentPart.onSave(POIXMLDocumentPart.java:472)
at org.apache.poi.ooxml.POIXMLDocument.write(POIXMLDocument.java:221)
=========================
It's not a solution, but it will work if you mop up the exception here.
(The stack trace above is the output from here.)
=========================
I wrote the values of some runtime variables in comments.
org.apache.poi.xssf.usermodel.XSSFRow
private void fixupCTCells(CTCell[] cArrayOrig) {
// copy all values to 2nd array and a map for lookup of index
CTCell[] cArrayCopy = new CTCell[cArrayOrig.length];
IdentityHashMap<CTCell, Integer> map = new
IdentityHashMap<>(_cells.size());
int i = 0;
for (CTCell ctCell : cArrayOrig) {
cArrayCopy[i] = (CTCell) ctCell.copy();
map.put(ctCell, i);
i++;
}
// populate _row.cArray correctly
i = 0;
for (XSSFCell cell : _cells.values()) {
// no need to change anything if position is correct
Integer correctPosition = map.get(cell.getCTCell());
Objects.requireNonNull(correctPosition, "Should find CTCell in
_row");
if(correctPosition != i) {
// we need to re-populate this CTCell
_row.setCArray(i, cArrayCopy[correctPosition]);
cell.setCTCell(_row.getCArray(i));
}
i++;
}
// remove any remaining illegal references in _rows.cArray
while (cArrayOrig.length > _cells.size()) { //debug cArrayOrig.length
is 59 _cells.size() is 23
try {
_row.removeC(_cells.size());
} catch (IndexOutOfBoundsException e) {
e.printStackTrace();// here here here here here
}
}
}
Xobj
public void remove_element(QName name/*debug
http://schemas.openxmlformats.org/spreadsheetml/2006/main and c */, int
i/*debug 0*/) {
if (i < 0) {
throw new IndexOutOfBoundsException();
}
if (!isContainer()) {
throw new IllegalStateException();
}
Xobj x;
for (x = _firstChild; x != null; x = x._nextSibling) {
if (x.isElem() && x._name.equals(name) && --i < 0) {
break;
}
}
removeElement(x);
}
CTRowImpl
@Override
public void removeC(int i) {
synchronized (monitor()) {
check_orphaned();
get_store().remove_element(PROPERTY_QNAME[0], i/*debug 23*/);
}
}
=========================
=========================
=========================
Xobj
public void remove_element(QName name, int i) {
if (i < 0) {
throw new IndexOutOfBoundsException();
}
if (!isContainer()) {
throw new IllegalStateException();
}
Xobj x;
for (x = _firstChild; x != null; x = x._nextSibling) {
if (x._name.equals(name)) {
System.out.print("hit");
}
if (x.isElem() && x._name.equals(name) && --i < 0) {
break;
}
}
removeElement(x);
}
↑System.out.print("hit"); is called, but the variable `i` is decremented before
the reference, so when the condition is hit, `i` will be `0` and the condition
will not be met.
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]