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.
Still present (3.8b4)
+1 same happens with 3.8beta4
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).
(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.
*** Bug 53147 has been marked as a duplicate of this bug. ***
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.
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.
Created attachment 29034 [details] Patch Fixes order of 'records' list in InternalWorkbook.setSheetOrder + test case.
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 :)