You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ta...@apache.org on 2016/11/22 14:47:45 UTC

svn commit: r1770848 - in /poi/trunk/src/ooxml: java/org/apache/poi/xssf/model/StylesTable.java testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java

Author: tallison
Date: Tue Nov 22 14:47:45 2016
New Revision: 1770848

URL: http://svn.apache.org/viewvc?rev=1770848&view=rev
Log:
bug 60343, return null if index is out of bounds in StylesTable's getStyleAt(idx)

Modified:
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java?rev=1770848&r1=1770847&r2=1770848&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java Tue Nov 22 14:47:45 2016
@@ -403,9 +403,18 @@ public class StylesTable extends POIXMLD
         return putFont(font, false);
     }
 
+    /**
+     *
+     * @param idx style index
+     * @return XSSFCellStyle or null if idx is out of bounds for xfs array
+     */
     public XSSFCellStyle getStyleAt(int idx) {
         int styleXfId = 0;
 
+        if (idx < 0 || idx >= xfs.size()) {
+            //BUG-60343
+            return null;
+        }
         // 0 is the empty default
         if(xfs.get(idx).getXfId() > 0) {
             styleXfId = (int) xfs.get(idx).getXfId();

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java?rev=1770848&r1=1770847&r2=1770848&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java Tue Nov 22 14:47:45 2016
@@ -463,10 +463,8 @@ public final class TestXSSFWorkbook exte
         // Should have one style
         assertEquals(1, wb1.getNumCellStyles());
         wb1.getCellStyleAt((short)0);
-        try {
-            wb1.getCellStyleAt((short)1);
-            fail("Shouldn't be able to get style at 1 that doesn't exist");
-        } catch(IndexOutOfBoundsException e) {}
+        assertNull("Shouldn't be able to get style at 0 that doesn't exist",
+                wb1.getCellStyleAt((short)1));
 
         // Add another one
         CellStyle cs = wb1.createCellStyle();
@@ -476,20 +474,16 @@ public final class TestXSSFWorkbook exte
         assertEquals(2, wb1.getNumCellStyles());
         wb1.getCellStyleAt((short)0);
         wb1.getCellStyleAt((short)1);
-        try {
-            wb1.getCellStyleAt((short)2);
-            fail("Shouldn't be able to get style at 2 that doesn't exist");
-        } catch(IndexOutOfBoundsException e) {}
+        assertNull("Shouldn't be able to get style at 2 that doesn't exist",
+                wb1.getCellStyleAt((short)2));
 
         // Save and reload
         XSSFWorkbook nwb = XSSFTestDataSamples.writeOutAndReadBack(wb1);
         assertEquals(2, nwb.getNumCellStyles());
         nwb.getCellStyleAt((short)0);
         nwb.getCellStyleAt((short)1);
-        try {
-            nwb.getCellStyleAt((short)2);
-            fail("Shouldn't be able to get style at 2 that doesn't exist");
-        } catch(IndexOutOfBoundsException e) {}
+        assertNull("Shouldn't be able to get style at 2 that doesn't exist",
+                nwb.getCellStyleAt((short)2));
 
         // Now with an existing file
         XSSFWorkbook wb2 = XSSFTestDataSamples.openSampleWorkbook("sample.xlsx");
@@ -497,10 +491,8 @@ public final class TestXSSFWorkbook exte
         wb2.getCellStyleAt((short)0);
         wb2.getCellStyleAt((short)1);
         wb2.getCellStyleAt((short)2);
-        try {
-            wb2.getCellStyleAt((short)3);
-            fail("Shouldn't be able to get style at 3 that doesn't exist");
-        } catch(IndexOutOfBoundsException e) {}
+        assertNull("Shouldn't be able to get style at 3 that doesn't exist",
+                wb2.getCellStyleAt((short)3));
 
         wb2.close();
         wb1.close();



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org