You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by bu...@apache.org on 2016/06/06 12:12:32 UTC

[Bug 59665] New: Using HSSFWorkbook#setSheetOrder to move sheets to the end corrupts bspos value in WorkbookRecordList

https://bz.apache.org/bugzilla/show_bug.cgi?id=59665

            Bug ID: 59665
           Summary: Using HSSFWorkbook#setSheetOrder to move sheets to the
                    end corrupts bspos value in WorkbookRecordList
           Product: POI
           Version: unspecified
          Hardware: All
                OS: All
            Status: NEW
          Severity: regression
          Priority: P2
         Component: HSSF
          Assignee: dev@poi.apache.org
          Reporter: msww-asfbugs@corefiling.co.uk

Created attachment 33914
  --> https://bz.apache.org/bugzilla/attachment.cgi?id=33914&action=edit
Patch which sets the value of bspos

Since POI 3.10, the setSheetOrder method on HSSFWorkbook corrupts internal
state when used to move a sheet to the end of the workbook. Specifically, such
a move results in the value of bspos in the WorkbookRecordList being reduced by
one from the correct value, with the result that all future uses of that field
to locate records get the wrong record.

For example, the following code

============
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

public class Demo {

  public static void main(String ... args) throws Exception {
    final HSSFWorkbook test = new HSSFWorkbook();
    test.createSheet("A");
    for (int i=0; i<70; i++) {
      test.setSheetOrder("A", 0);
    }
  }
}
============

will throw an exception after 62 iterations:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1
    at java.util.ArrayList.elementData(ArrayList.java:418)
    at java.util.ArrayList.get(ArrayList.java:431)
    at
org.apache.poi.hssf.model.WorkbookRecordList.get(WorkbookRecordList.java:50)
    at
org.apache.poi.hssf.model.InternalWorkbook.setSheetOrder(InternalWorkbook.java:649)
    at
org.apache.poi.hssf.usermodel.HSSFWorkbook.setSheetOrder(HSSFWorkbook.java:489)
    at Demo.main(Demo.java:10)


This happens because the removal of the bound sheet record in
InternalWorkbook#setSheetOrder reduces the value of bspos by one, but when the
record is added back, the position it is placed in is after what is now the
last bound sheet record, so bspos is not incremented. Each iteration then
reduces bspos by one, until it results in POI trying to fetch records from
outside the bounds of the list.

This behaviour was introduced by the fix for Bug 50298 in commit
https://svn.apache.org/repos/asf/poi/trunk@1516313. Before that, POI did not
reorder the records in this scenario.

Please find attached a patch which sets the value of bspos following the sheet
move, which fixes the observed issue.

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 59665] [Patch] Using HSSFWorkbook#setSheetOrder to move sheets to the end corrupts bspos value in WorkbookRecordList

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=59665

Dominik Stadler <do...@gmx.at> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|NEW                         |RESOLVED

--- Comment #2 from Dominik Stadler <do...@gmx.at> ---
Looks reasonable, applied via r1753038, thanks for the patch!

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 59665] [Patch] Using HSSFWorkbook#setSheetOrder to move sheets to the end corrupts bspos value in WorkbookRecordList

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=59665

Dominik Stadler <do...@gmx.at> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |PatchAvailable

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 59665] [Patch] Using HSSFWorkbook#setSheetOrder to move sheets to the end corrupts bspos value in WorkbookRecordList

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=59665

David North <dt...@corefiling.co.uk> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Using                       |[Patch] Using
                   |HSSFWorkbook#setSheetOrder  |HSSFWorkbook#setSheetOrder
                   |to move sheets to the end   |to move sheets to the end
                   |corrupts bspos value in     |corrupts bspos value in
                   |WorkbookRecordList          |WorkbookRecordList

--- Comment #1 from David North <dt...@corefiling.co.uk> ---
Patch looks believable to me, but it would be good to have review from someone
more familiar with HSSF.

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org