Bug 59983 - [PATCH] Wrong update of shared formulas after shiftRow
Summary: [PATCH] Wrong update of shared formulas after shiftRow
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 3.16-dev
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
Keywords: PatchAvailable
Depends on:
Reported: 2016-08-11 15:26 UTC by Luca Martini
Modified: 2017-02-08 07:23 UTC (History)
1 user (show)

failing unit test patch (8.28 KB, application/gzip)
2016-08-11 15:26 UTC, Luca Martini
patch containing modification to src and test code (7.75 KB, application/zip)
2017-02-06 14:42 UTC, Chiara Marcheschi

Note You need to log in before you can comment on or make changes to this bug.
Description Luca Martini 2016-08-11 15:26:38 UTC
Created attachment 34129 [details]
failing unit test patch

It seems that the shiftRow method does not correctly handle shared formulas.
I provide a failing unit test that higlights the problem.
It seems that when updating a shared formula, the code also updates the range it is applied to.
However, also the cells that are in the range are updated too, thus resulting in a double shift of the formula text and then in a not valid.

I think the problem is in the class XSSFRowShifter, method updateRowFormulas.

Comment 1 Javen O'Neal 2016-09-21 05:23:07 UTC
Thanks for the unit test! Applied in r1761673.
I can verify that the shared formula is being shifted twice.

Testcase: testSharedFormulas took 0.004 sec
        SKIPPED: This test currently fails with org.junit.ComparisonFailure: expected:<SUM(D[2:D5])> but was:<SUM(D[3:D6])>
Comment 2 Chiara Marcheschi 2017-02-06 14:42:47 UTC
Created attachment 34720 [details]
patch containing modification to src and test code

Bug fix and unit test
Comment 3 Chiara Marcheschi 2017-02-06 14:54:10 UTC
The bug was due to a missing update of the CTCellFormula data structure related to the shared formula; in particular, the "ref" attribute was not updated during a row shift.

The submitted patch contains the bug fix and a unit test that uses an xlsx file which is also attached.
Comment 4 Javen O'Neal 2017-02-08 07:21:18 UTC
Thanks for the patch! Applied in r1782111.

Will be included in POI 3.16 beta 3.