bengbengbalabalabeng commented on issue #676:
URL: https://github.com/apache/fesod/issues/676#issuecomment-3491134695
I've been looking at the implementation of `CsvRow#getCell(int)`.
```java
public Cell getCell(int cellnum) {
if (cellnum >= cellList.size()) {
return null;
}
return cellList.get(cellnum - 1);
}
```
In this method, the parameter `cellnum` is expected, according to the Apache
POI contract, to be a 0‑based column index. However, the current implementation
uses `cellnum - 1` when accessing `cellList`, which effectively shifts the
logic to a 1‑based index. At the same time, the method also applies the
boundary check `cellnum >= cellList.size()`.
Results in an off‑by‑one error:
- If `cellnum` is treated as 1‑based, the last element can never be
accessed.
- If `cellnum` is treated as 0‑based, the subtraction (`cellnum - 1`) leads
to an `IndexOutOfBoundsException`.
It's worth noting that `CsvRow#getFirstCellNum()` correctly adheres to the
0-based indexing convention, returning 0 for the first column. Therefore,
CsvRow#getCell(int) should also be aligned to use a 0-based index to fix this
issue.
```java
public short getFirstCellNum() {
if (CollectionUtils.isEmpty(cellList)) {
return -1;
}
return 0;
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]