Bug 59733 - shiftRows() causes org.apache.xmlbeans.impl.values.XmlValueDisconnectedException
Summary: shiftRows() causes org.apache.xmlbeans.impl.values.XmlValueDisconnectedExcep...
Status: NEW
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
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-06-20 10:17 UTC by Dattathreya
Modified: 2016-11-23 11:31 UTC (History)
0 users



Attachments

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.createCell(0).setCellValue(1.0);
		row.createCell(1).setCellValue(2.0);
		//
		row = workbook.getSheet("mySheet").createRow(1);
		row.createCell(0).setCellValue(3.0);
		row.createCell(1).setCellValue(4.0);
		row = workbook.getSheet("mySheet").createRow(2);
		row.createCell(0).setCellValue(5.0);
		row.createCell(1).setCellValue(6.0);
		row = workbook.getSheet("mySheet").createRow(3);
		row.createCell(0).setCellValue(7.0);
		row.createCell(1).setCellValue(8.0);
		row = workbook.getSheet("mySheet").createRow(4);
		row.createCell(0).setCellValue(9.0);
		row.createCell(1).setCellValue(10.0);

		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++) {
    sheet.createRow(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.

//worksheet.getSheetData().removeRow(idx);
for(Iterator<Cell> cit = row.cellIterator(); cit.hasNext();) {
   row.removeCell(cit.next());
}