Bug 49864 - documentation of getLastCellNum changes is missing
Summary: documentation of getLastCellNum changes is missing
Status: RESOLVED WONTFIX
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.0-FINAL
Hardware: PC All
: P2 enhancement (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-09-02 12:17 UTC by Florian R.
Modified: 2011-06-24 09:57 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Florian R. 2010-09-02 12:17:30 UTC
Can you please add the following change to the changelog:

Somewhere between 2.5.1-FINAL and 3.0-FINAL in org.apache.poi.hssf.usermodel.HSSFRow the method getLastCellNum changed from 
"get the number of the last cell contained in this row."
to
"Gets the index of the last cell contained in this row PLUS ONE."

This is IMHO one of the most important changes between 2.5.1 and 3.x because it breaks existing functionality (and it took me lots of time to find this unmentioned change during upgrading as 3.2 produces only an NPE when accessing nonexistent cells...)

Thank you very much!
Comment 1 Nick Burch 2010-09-06 11:25:25 UTC
It's so long since POI 2.5.x that I can't remember for sure... However I seem to recall that there was a bug and some files returned the last cell index plus one, and some the last index. This was fixed to always be plus one.

Someone else might be able to confirm or deny this though?

Otherwise, you may find the iterators (introduced in 3.5) much easier to work with, see http://poi.apache.org/spreadsheet/quick-guide.html#Iterator
Comment 2 Florian R. 2010-09-08 10:58:06 UTC
if you compare the javadocs of getLastCellNum() of
http://archive.apache.org/dist/jakarta/poi/release/bin/poi-bin-2.5.1-final-20040804.zip
and
http://archive.apache.org/dist/jakarta/poi/release/bin/poi-bin-3.0-FINAL-20070503.zip

at this position:

poi-bin-2.5.1-final-20040804.zip/docs/apidocs/org/apache/poi/hssf/usermodel/HSSFRow.html
with
poi-bin-3.2-FINAL-20081019.zip/poi-3.2-FINAL/docs/apidocs/org/apache/poi/hssf/usermodel/HSSFRow.html

you can see there was a change.


Thanks for the iterator hint, I'll take a look at it.
Comment 3 Yegor Kozlov 2011-06-24 09:57:43 UTC
The "plus one" change was made intentionally, the main goal was to make lastCellNum the standard upper bound when iterating over cells:

      int minColIx = row.getFirstCellNum();
      int maxColIx = row.getLastCellNum();
      for(int colIx = minColIx; colIx < maxColIx; colIx++) {
        Cell cell = row.getCell(colIx);
        //... do something with cell
      }

It might had broke the code written for POI 2.5.1, but on the other hand it prevented incorrect usages of lastCellNum  in 'for' loops which seemed more important at that time.

Yegor

(In reply to comment #2)
> if you compare the javadocs of getLastCellNum() of
> http://archive.apache.org/dist/jakarta/poi/release/bin/poi-bin-2.5.1-final-20040804.zip
> and
> http://archive.apache.org/dist/jakarta/poi/release/bin/poi-bin-3.0-FINAL-20070503.zip
> 
> at this position:
> 
> poi-bin-2.5.1-final-20040804.zip/docs/apidocs/org/apache/poi/hssf/usermodel/HSSFRow.html
> with
> poi-bin-3.2-FINAL-20081019.zip/poi-3.2-FINAL/docs/apidocs/org/apache/poi/hssf/usermodel/HSSFRow.html
> 
> you can see there was a change.
> 
> 
> Thanks for the iterator hint, I'll take a look at it.