Bug 48202 - CellRangeUtil.mergeCellRanges() causes UnsupportedOperationException due to modifying a read-only list
Summary: CellRangeUtil.mergeCellRanges() causes UnsupportedOperationException due to m...
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.5-FINAL
Hardware: PC Windows Vista
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Reported: 2009-11-16 02:52 UTC by Karl Eilebrecht
Modified: 2009-12-19 03:33 UTC (History)
1 user (show)


Note You need to log in before you can comment on or make changes to this bug.
Description Karl Eilebrecht 2009-11-16 02:52:17 UTC
Steps to reproduce:
- create an array of CellRangeAddress objects, where at least two are direct 
- call CellRangeUtil.mergeCellRanges(array)
- You should see an UnsupportedOperationException thrown by AbstractList

The public method CellRangeUtil.mergeCellRanges() wraps an array into an ArrayList using Arrays.asList(...) to pass the result to the corresponding private method mergeCellRanges().

Under certain conditions mergeCellRanges() will try to shrink the list to a smaller size. The error occurs because structural modification of a wrapped Array is impossible.

Problem: CellRangeUtil line 99, error occurs at line 124

Proposed solution: Copy the array into a list rather than creating a list view of the array.
Comment 1 Yegor Kozlov 2009-12-19 03:33:15 UTC
Fixed in r892462, junit added. 

Your proposed solution is correct: the List in mergeCellRanges can be structurally modified and this method should copy the input array into the list, not use a list view of the input array.