poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cen...@apache.org
Subject svn commit: r1686564 - in /poi/trunk/src: java/org/apache/poi/ss/formula/functions/Sumif.java ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java testcases/org/apache/poi/ss/formula/functions/TestSumif.java
Date Sat, 20 Jun 2015 11:29:15 GMT
Author: centic
Date: Sat Jun 20 11:29:14 2015
New Revision: 1686564

URL: http://svn.apache.org/r1686564
Log:
Bug 56420: Fix possible NullPointerException when empty cell is included in Sumif calculation

Modified:
    poi/trunk/src/java/org/apache/poi/ss/formula/functions/Sumif.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
    poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestSumif.java

Modified: poi/trunk/src/java/org/apache/poi/ss/formula/functions/Sumif.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/formula/functions/Sumif.java?rev=1686564&r1=1686563&r2=1686564&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/formula/functions/Sumif.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/formula/functions/Sumif.java Sat Jun 20 11:29:14
2015
@@ -69,6 +69,12 @@ public final class Sumif extends Var2or3
 			AreaEval aeSum) {
 		// TODO - junit to prove last arg must be srcColumnIndex and not srcRowIndex
 		I_MatchPredicate mp = Countif.createCriteriaPredicate(arg1, srcRowIndex, srcColumnIndex);
+		
+		// handle empty cells
+		if(mp == null) {
+		    return NumberEval.ZERO;
+		}
+
 		double result = sumMatchingCells(aeRange, mp, aeSum);
 		return new NumberEval(result);
 	}

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java?rev=1686564&r1=1686563&r2=1686564&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java Sat Jun
20 11:29:14 2015
@@ -1538,7 +1538,6 @@ public final class TestXSSFBugs extends
      * SUMIF was throwing a NPE on some formulas
      */
     @Test
-    @Ignore("This bug is still to be fixed")
     public void testBug56420SumIfNPE() throws Exception {
         XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("56420.xlsx");
         
@@ -1548,7 +1547,8 @@ public final class TestXSSFBugs extends
         Row r = sheet.getRow(2);
         Cell c = r.getCell(2);
         assertEquals("SUMIF($A$1:$A$4,A3,$B$1:$B$4)", c.getCellFormula());
-        evaluator.evaluateInCell(c);
+        Cell eval = evaluator.evaluateInCell(c);
+        assertEquals(0.0, eval.getNumericCellValue(), 0.0001);
     }
 
     private void bug53798Work(Workbook wb, File xlsOutput) throws IOException {

Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestSumif.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestSumif.java?rev=1686564&r1=1686563&r2=1686564&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestSumif.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestSumif.java Sat Jun 20
11:29:14 2015
@@ -21,6 +21,8 @@ import junit.framework.AssertionFailedEr
 import junit.framework.TestCase;
 
 import org.apache.poi.ss.formula.eval.AreaEval;
+import org.apache.poi.ss.formula.eval.BlankEval;
+import org.apache.poi.ss.formula.eval.ErrorEval;
 import org.apache.poi.ss.formula.eval.NumberEval;
 import org.apache.poi.ss.formula.eval.NumericValueEval;
 import org.apache.poi.ss.formula.eval.StringEval;
@@ -107,4 +109,11 @@ public final class TestSumif extends Tes
 
 		confirmDouble(60, ve);
 	}
+
+	public void testEvaluateException() {
+	    assertEquals(ErrorEval.VALUE_INVALID, invokeSumif(-1, -1, BlankEval.instance, new NumberEval(30.0)));
+        assertEquals(ErrorEval.VALUE_INVALID, invokeSumif(-1, -1, BlankEval.instance, new
NumberEval(30.0), new NumberEval(30.0)));
+        assertEquals(ErrorEval.VALUE_INVALID, invokeSumif(-1, -1, new NumberEval(30.0), BlankEval.instance,
new NumberEval(30.0)));
+        assertEquals(ErrorEval.VALUE_INVALID, invokeSumif(-1, -1, new NumberEval(30.0), new
NumberEval(30.0), BlankEval.instance));
+	}
 }



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


Mime
View raw message