poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gal...@apache.org
Subject svn commit: r1850207 - in /poi/trunk/src: ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java testcases/org/apache/poi/ss/usermodel/BaseTestCell.java
Date Wed, 02 Jan 2019 20:45:53 GMT
Author: gallon
Date: Wed Jan  2 20:45:52 2019
New Revision: 1850207

URL: http://svn.apache.org/viewvc?rev=1850207&view=rev
Log:
Bug 62307: made Cell#getNumericCellValue() behavior consistent across HSSF/XSSF/SXSSF.\nAll
three implementations throw ISE when trying to get numeric value from a boolean-valued cell,
have it a formula set or not.

Modified:
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java
    poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java?rev=1850207&r1=1850206&r2=1850207&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java Wed Jan  2 20:45:52
2019
@@ -285,12 +285,10 @@ public final class XSSFCell implements C
      */
     @Override
     public double getNumericCellValue() {
-        CellType cellType = getCellType();
-        switch(cellType) {
+        CellType valueType = isFormulaCell() ? getCachedFormulaResultType() : getCellType();
+        switch(valueType) {
             case BLANK:
                 return 0.0;
-            case FORMULA:
-                // fall-through
             case NUMERIC:
                 if(_cell.isSetV()) {
                    String v = _cell.getV();
@@ -305,8 +303,10 @@ public final class XSSFCell implements C
                 } else {
                    return 0.0;
                 }
+            case FORMULA:
+                throw new AssertionError();
             default:
-                throw typeMismatch(CellType.NUMERIC, cellType, false);
+                throw typeMismatch(CellType.NUMERIC, valueType, false);
         }
     }
 
@@ -1361,4 +1361,4 @@ public final class XSSFCell implements C
     }
         
 }
-    
\ No newline at end of file
+    

Modified: poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java?rev=1850207&r1=1850206&r2=1850207&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java Wed Jan  2 20:45:52
2019
@@ -74,7 +74,7 @@ public abstract class BaseTestCell {
         assertEquals(CellType.BOOLEAN, cell.getCellType());
         cell.setCellValue(true);
         assertTrue(cell.getBooleanCellValue());
-        assertProhibitedValueAccess(cell, CellType.NUMERIC, CellType.STRING,
+        assertProhibitedValueAccess(cell, CellType.NUMERIC, CellType.STRING, CellType.BOOLEAN,
                 CellType.FORMULA, CellType.ERROR);
 
         cell.setCellValue(factory.createRichTextString("Foo"));
@@ -1133,4 +1133,11 @@ public abstract class BaseTestCell {
             assertEquals(CellType.FORMULA, cell.getCellType());
         }
     }
+
+    @Test
+    public void testGetNumericCellValueOnABlankCellReturnsZero() {
+        Cell cell = _testDataProvider.createWorkbook().createSheet().createRow(0).createCell(0);
+        assertEquals(CellType.BLANK, cell.getCellType());
+        assertEquals(0, cell.getNumericCellValue(), 0);
+    }
 }



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


Mime
View raw message