Bug 53798 - negative row shift causes corrupted data or throws exception
Summary: negative row shift causes corrupted data or throws exception
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 3.9-FINAL
Hardware: All All
: P2 critical with 4 votes (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Reported: 2012-08-29 13:06 UTC by Andrew Wdziekonski
Modified: 2015-10-11 09:47 UTC (History)
2 users (show)

NegativeShiftBug.java (3.17 KB, application/octet-stream)
2012-08-29 13:06 UTC, Andrew Wdziekonski
shiftNegative_TMPL.xlsx (template) (9.16 KB, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
2012-08-29 13:08 UTC, Andrew Wdziekonski

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Wdziekonski 2012-08-29 13:06:44 UTC
Created attachment 29298 [details]

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.
Comment 1 Andrew Wdziekonski 2012-08-29 13:08:53 UTC
Created attachment 29299 [details]
shiftNegative_TMPL.xlsx (template)
Comment 2 greeson1 2013-02-14 00:30:01 UTC
I have observed this bug is 3.8 I am assuming it  is the same bug.
Comment 3 Andrew Wdziekonski 2013-02-14 14:26:24 UTC
(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.
Comment 4 Dominik Stadler 2013-09-09 09:44:01 UTC
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.