Bug 59733 - shiftRows() causes org.apache.xmlbeans.impl.values.XmlValueDisconnectedException
Summary: shiftRows() causes org.apache.xmlbeans.impl.values.XmlValueDisconnectedExcep...
Status: RESOLVED DUPLICATE of bug 64516
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: unspecified
Hardware: PC Windows NT
: P2 normal with 6 votes (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Blocks: 58221
  Show dependency tree
Reported: 2016-06-20 10:17 UTC by Dattathreya
Modified: 2020-10-25 21:10 UTC (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
Description Dattathreya 2016-06-20 10:17:27 UTC
Problem can be reproduced by following these steps.

1] Shift Row2 to Row0
2] Now try shifting Row3 to Row0 you get org.apache.xmlbeans.impl.values.XmlValueDisconnectedException

Here is piece of code to reproduce issue. This issue happens with 3.15-beta as well.

Workbook workbook = new XSSFWorkbook();
		Sheet sheet = workbook.createSheet("mySheet");
		Row row = workbook.getSheet("mySheet").createRow(0);
		row = workbook.getSheet("mySheet").createRow(1);
		row = workbook.getSheet("mySheet").createRow(2);
		row = workbook.getSheet("mySheet").createRow(3);
		row = workbook.getSheet("mySheet").createRow(4);

		sheet.shiftRows(2, 2, -2);
		sheet.shiftRows(3, 3, -3);
Comment 1 Javen O'Neal 2016-06-20 10:44:57 UTC
Verified this affects the current trunk (pre-3.15-beta2). Added a disabled unit test in r1749295.

XmlValueDisconnectedExceptions occur because the links between nodes in the DOM (XML tree) are broken. This can happen when a node is freed by one node but still weakly linked to by another node. This only causes problems when the second node tries to traverse the broken link.
Comment 2 Dominik Stadler 2016-06-20 10:52:21 UTC
Probably a duplicate of bug 58221
Comment 3 Javen O'Neal 2016-06-20 10:54:09 UTC
I simplified this to creating empty rows, and the exception was still thrown by the second shiftRows call. r1749300.
This isolates the problem to the CTRows causing the disconnected XML value.

Workbook workbook = new XSSFWorkbook();
Sheet sheet = workbook.createSheet();
for (int r=0; r<=4; r++) {

// Shift the 2nd row on top of the 0th row
sheet.shiftRows(2, 2, -2);
sheet.shiftRows(3, 3, -3);
Comment 4 Dattathreya 2016-06-20 11:28:48 UTC
Will it be fixed in 3.15?
Comment 5 Javen O'Neal 2016-06-20 11:34:08 UTC
(In reply to Dattathreya from comment #4)
> Will it be fixed in 3.15?
It depends on if someone contributes a patch that fixes the bug. Those who are not affected by the bug are less likely to spend time fixing the bug.
Comment 6 Dattathreya 2016-06-20 14:04:06 UTC
Is there any temporary workarounds available for this problem?
Comment 7 Dominik Stadler 2016-07-16 20:53:30 UTC
In r1752996 I have narrowed down the testcase slightly, after the first shifting, only removing row 0 and then trying to access row 1 causes the exception.
Comment 8 Sebastiaan Blommers 2016-11-23 11:31:49 UTC
By experiment I uncommented removeRow on the sheetData in XSSFSheets.shiftRows function. Because this decouples the original row from the xml. I now try and remove all cells instead when code decides to remove the row(s) to shift to.

for(Iterator<Cell> cit = row.cellIterator(); cit.hasNext();) {
Comment 9 Dominik Stadler 2020-10-25 21:09:37 UTC
The related test-case was fixed as part of bug #64516, so hopefully this problem is now resolved in nightly builds, although there remain some more issues with shifting/cloning...

*** This bug has been marked as a duplicate of bug 64516 ***
Comment 10 Dominik Stadler 2020-10-25 21:10:20 UTC
The related test-case was fixed as part of bug #64516, so hopefully this problem is now resolved in nightly builds, although there remain some more issues with shifting/cloning...