Created attachment 29298 [details] NegativeShiftBug.java Hi All, I found a bug in the XSSF implementation of Sheet.shiftRows() method which causes either a corrupted data for the shifted row in xlsx file or throws org.apache.xmlbeans.impl.values.XmlValueDisconnectedException depending on a scenario. It can be observed in the following scenarios: Result: corrupted data in the shifted row 1) negative shifting row(s) by less than -1 2) after a negative shift = -1 (less than -1 see above) attempt to create a new row IN PLACE of a removed row by a negative shift causes corrupted xlsx file with unreadable data in the negative shifted row. Result: thrown org.apache.xmlbeans.impl.values.XmlValueDisconnectedException 3) once a negative shift has been made any attempt to shift another group of rows (note: outside of previously negative shifted rows) by a POSITIVE amount causes POI exception org.apache.xmlbeans.impl.values.XmlValueDisconnectedException. NOTE: another negative shift on another group of rows is successful, provided no new rows in place of previously shifted rows were attempted to be created as explained above. Please see the attached NegativeShiftBug.java in combination with template .xlsx file illustrating the problem. Please NOTE that HSSF shiftRows() implementation has none of the problems discussed above.
Created attachment 29299 [details] shiftNegative_TMPL.xlsx (template)
I have observed this bug is 3.8 I am assuming it is the same bug.
(In reply to comment #2) > I have observed this bug is 3.8 I am assuming it is the same bug. As I'm aware this bug has been in all previous versions. I have tested all versions since 3.7.
I finally was able to narrow this down and find the root-cause of this problem. It seems the handling of rows that are overwritten by the shifting was done incorrectly in some cases, thus leaving behind left-over objects which caused these exceptions when being accessed. This should be fixed with r1521012, we now first ensure that all removed/overwritten rows are removed and only then apply the shifting, now this test-case and all existing tests seem to run fine. Let's see which other bugs in this area this might also fix.