Bug 50083 - Workbook.setSheetOrder does not fixup record list
Summary: Workbook.setSheetOrder does not fixup record list
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.6-FINAL
Hardware: All All
: P2 major (vote)
Target Milestone: ---
Assignee: POI Developers List
: 53147 (view as bug list)
Depends on:
Reported: 2010-10-13 08:02 UTC by Richard Evans
Modified: 2013-08-21 23:11 UTC (History)
1 user (show)

Simple test case with input files to demonstrate the issue. (11.48 KB, application/java-archive)
2011-06-30 15:19 UTC, Jon Svede
patch for version 3.8 (789 bytes, patch)
2012-04-26 13:23 UTC, recyclebin5385
Details | Diff
Minimal test case (3.34 KB, application/octet-stream)
2012-07-03 14:25 UTC, Rémy LeBeau
Patch (2.31 KB, patch)
2012-07-05 13:26 UTC, Rémy LeBeau
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Evans 2010-10-13 08:02:55 UTC
Workbook.setSheetOrder correcly changes the ordering in the internal boundsheets list _but does not_ reorder the corresponding BoundSheetRecord instances in the records list.

If subsequently a sheet is removed, the wrong BoundSheetRecord instance will get removed from the record list, leading to serialization errors when the workbook is written because the calculated size of the workbook data is based on the records list, whist the sheet records are serialized using the boundsheets list.

This problem is also present in 3.7beta3.  It it probably the root cause of bug 48294.
Comment 1 Antti Koskimäki 2011-06-29 04:56:56 UTC
Still present (3.8b4)
Comment 2 Hamza 2011-06-30 07:38:00 UTC
+1 same happens with 3.8beta4
Comment 3 Jon Svede 2011-06-30 15:19:26 UTC
Created attachment 27231 [details]
Simple test case with input files to demonstrate the issue.

Attaching my test case to reproduce the issue.  To enable the code that creates the error, pass any argument to the class when you run it.  If you do not, the class will run fine (i.e., no exception).
Comment 4 Jon Svede 2011-06-30 15:21:02 UTC
(In reply to comment #3)
This test case was exercised against POI 3.8 Beta 3 - not aware of a POI 3.8 Beta 4 version at this time.
Comment 5 recyclebin5385 2012-04-26 13:20:48 UTC
*** Bug 53147 has been marked as a duplicate of this bug. ***
Comment 6 recyclebin5385 2012-04-26 13:23:22 UTC
Created attachment 28685 [details]
patch for version 3.8

Still present in version 3.8 final (and probably the trunk of the repository).

I wrote a patch to fix this problem.
Comment 7 Rémy LeBeau 2012-07-03 14:25:25 UTC
Created attachment 29024 [details]
Minimal test case

Minimal reproduction of the same exception as the previous test case (27231),
with an attempt to explain the cause of it.
Comment 8 Rémy LeBeau 2012-07-05 13:26:47 UTC
Created attachment 29034 [details]

Fixes order of 'records' list in InternalWorkbook.setSheetOrder + test case.
Comment 9 Dominik Stadler 2013-08-21 23:11:24 UTC
This was fixed in Bug 50298 before I found the patch in this Bug, incidentially I fixed it in a very similar way, so it seems to be the right thing to do :)