Bug 50416 - shiftRows compute wrong the last row number
Summary: shiftRows compute wrong the last row number
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.7-FINAL
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-12-06 05:37 UTC by French.Koala
Modified: 2010-12-14 01:41 UTC (History)
0 users



Attachments
Test case which describe the bug (1.37 KB, text/plain)
2010-12-13 07:59 UTC, French.Koala
Details

Note You need to log in before you can comment on or make changes to this bug.
Description French.Koala 2010-12-06 05:37:36 UTC
In org.apache.poi.hssf.usermodel.HSSFSheet,

in method public void shiftRows(int startRow, int endRow, int n,
            boolean copyRowHeight, boolean resetOriginalRowHeight, boolean moveComments), 
the line if ( endRow == _lastrow || endRow + n > _lastrow ) _lastrow = Math.min( endRow + n, SpreadsheetVersion.EXCEL97.getLastRowIndex() ); compute the _lastrow if the end == lastrow and n is NEGATIVE.

Regards, F.K
Comment 1 Nick Burch 2010-12-13 00:53:05 UTC
I'm not sure I quite follow, sorry

Could you write up a little unit test that shows the problem? Or describe what parameters to pass to shiftRows to make it compute it wrong?
Comment 2 French.Koala 2010-12-13 07:59:41 UTC
Created attachment 26399 [details]
Test case which describe the bug
Comment 3 French.Koala 2010-12-13 08:00:54 UTC
Sorry for the description, so please find the attached unitTest which describe the bug.

Regards, F.K
Comment 4 Nick Burch 2010-12-14 01:41:32 UTC
I've found the problem. In the case of:

* 1
* blank
* 3
* 4

Then when you move 4 to (blank=2) with a shift of 2, it wasn't checking if row 3 existed or not before re-computing the last

In the case of

* 1
* 2
* 3

then moving row 1 to row 4 would also have left it confused

I think I've fixed this in r1048951, along with a slightly expanded version of your unit test (thanks for that!)