[ https://issues.apache.org/jira/browse/ODFTOOLKIT-356?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15000612#comment-15000612 ]
Raimund Hölle edited comment on ODFTOOLKIT-356 at 11/11/15 5:29 PM: -------------------------------------------------------------------- And this is the reason and the solution: Original code (still in trunk): {code:title=Row.java|borderStyle=solid} public Cell getCellByIndex(int index) { ... // expand column as needed. int lastColumnIndex = table.getColumnCount() - 1; if (index > lastColumnIndex) { // need clean cell style. table.appendColumns((index - lastColumnIndex), true); } ... } {code} If getColumnCount() returns 0, the index for appendColumns() is -1. {code:title=Table.java|borderStyle=solid} public Column appendColumn() { ... List<Row> rowList = getRowList(); for (int i = 0; i < rowList.size();) { Row row1 = rowList.get(i); row1.insertCellBefore(row1.getCellByIndex(columnCount - 1), null); i = i + row1.getRowsRepeatedNumber(); } ... } {code} Corrected code: {code:title=Row.java|borderStyle=solid} table.appendColumns(lastColumnIndex < 0 ? index + 1 : (index - lastColumnIndex), true); {code} {code:title=Table.java|borderStyle=solid} if (columnCount > 0) { List<Row> rowList = getRowList(); for (int i = 0; i < rowList.size();) { ... } } } {code} I've tested that solution, it works. was (Author: profhccaesar): And this is the reason and the solution: Original code (still in trunk): {code:title=Row.java|borderStyle=solid} public Cell getCellByIndex(int index) { ... // expand column as needed. int lastColumnIndex = table.getColumnCount() - 1; if (index > lastColumnIndex) { // need clean cell style. table.appendColumns((index - lastColumnIndex), true); } ... } {code} If getColumnCount() returns 0, the index for appendColumns() is -1. Correct code: {code:title=Row.java|borderStyle=solid} table.appendColumns(lastColumnIndex < 0 ? index + 1 : (index - lastColumnIndex), true); {code} I've tested that solution, it works. > IllegalArgumentException when removing all columns from a fresh Table > --------------------------------------------------------------------- > > Key: ODFTOOLKIT-356 > URL: https://issues.apache.org/jira/browse/ODFTOOLKIT-356 > Project: ODF Toolkit > Issue Type: Bug > Affects Versions: 0.6-incubating > Reporter: Florian Hopf > Assignee: Florian Hopf > Attachments: ODFTOOLKIT-356-Test.patch > > > When trying to remove all columns from the Table of a newly created > SpreadsheetDocument an illegal index is passed in to Row#getCellByIndex() -- This message was sent by Atlassian JIRA (v6.3.4#6332)