You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by gw...@apache.org on 2018/09/19 17:42:43 UTC
svn commit: r1841357 - in /poi/trunk/src/ooxml:
java/org/apache/poi/xssf/usermodel/XSSFTable.java
testcases/org/apache/poi/xssf/usermodel/TestXSSFTable.java
Author: gwoolsey
Date: Wed Sep 19 17:42:43 2018
New Revision: 1841357
URL: http://svn.apache.org/viewvc?rev=1841357&view=rev
Log:
Bug 62740 - XSSFTable constructor automatically assigns invalid (non-unique) column IDs
fix the logic and update the unit test to check for and catch the problem.
Modified:
poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTable.java
poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFTable.java
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTable.java?rev=1841357&r1=1841356&r2=1841357&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTable.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTable.java Wed Sep 19 17:42:43 2018
@@ -283,7 +283,7 @@ public class XSSFTable extends POIXMLDoc
}
// check if name is unique and calculate unique column id
- long nextColumnId = 1;
+ long nextColumnId = 0;
for (XSSFTableColumn tableColumn : getColumns()) {
if (columnName != null && columnName.equalsIgnoreCase(tableColumn.getName())) {
throw new IllegalArgumentException("Column '" + columnName
@@ -291,6 +291,8 @@ public class XSSFTable extends POIXMLDoc
}
nextColumnId = Math.max(nextColumnId, tableColumn.getId());
}
+ // Bug #62740, the logic was just re-using the existing max ID, not incrementing beyond it.
+ nextColumnId++;
// Add the new Column
CTTableColumn column = columns.insertNewTableColumn(columnIndex);
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFTable.java?rev=1841357&r1=1841356&r2=1841357&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFTable.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFTable.java Wed Sep 19 17:42:43 2018
@@ -19,6 +19,7 @@ package org.apache.poi.xssf.usermodel;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
@@ -395,15 +396,21 @@ public final class TestXSSFTable {
assertEquals(2, table.getRowCount());
// add columns
- table.createColumn("Column B");
- table.createColumn("Column D");
- table.createColumn("Column C", 2); // add between B and D
+ XSSFTableColumn c1 = table.getColumns().get(0);
+ XSSFTableColumn cB = table.createColumn("Column B");
+ XSSFTableColumn cD = table.createColumn("Column D");
+ XSSFTableColumn cC = table.createColumn("Column C", 2); // add between B and D
table.updateReferences();
table.updateHeaders();
assertEquals(4, table.getColumnCount());
assertEquals(2, table.getRowCount());
+ // column IDs start at 1, and increase in the order columns are added (see bug #62740)
+ assertEquals("Column c ID", 1, c1.getId());
+ assertTrue("Column B ID", c1.getId() < cB.getId());
+ assertTrue("Column D ID", cB.getId() < cD.getId());
+ assertTrue("Column C ID", cD.getId() < cC.getId());
assertEquals("Column 1", table.getColumns().get(0).getName()); // generated name
assertEquals("Column B", table.getColumns().get(1).getName());
assertEquals("Column C", table.getColumns().get(2).getName());
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org