Bug 68231 - removeAllCells()@HSSFRow can raise an exception issue
Summary: removeAllCells()@HSSFRow can raise an exception issue
Status: RESOLVED WORKSFORME
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 5.3.x-dev
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-11-27 02:16 UTC by zhonghao
Modified: 2024-02-25 20:29 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description zhonghao 2023-11-27 02:16:18 UTC
The code is as follows:

 protected void removeAllCells() {
        for (HSSFCell cell : cells) {
            if (cell != null) {
                removeCell(cell, true);
            }
        }
        cells=new HSSFCell[INITIAL_CAPACITY];
    }

NPOI fixed a bug:
https://github.com/nissl-lab/npoi/commit/7a885c42e2f21147c1c4b744db55f6d4af1e69fc

The buggy code is as follows:

public void RemoveAllCells(){
 int initialLen = cells.Count;
 for (int i = 0; i < initialLen; i++){
   RemoveCell(cells[i], true);
}}

The fixed code is as follows:
public void RemoveAllCells(){
  foreach (ICell cell in cells.Values){
    RemoveCell(cell, true);
}}
Comment 1 PJ Fanning 2023-11-27 10:30:19 UTC
We are not going to just copy NPOI. Please provide real world examples. POI is a volunteer project and it is normally best to provide a patch with a test case yourself.
Comment 2 Dominik Stadler 2024-02-25 20:29:23 UTC
This is not an issue Apache POI as the cell-array is not changed when removing. Also it seems a similar change was already applied in 2016.