]> source.dussan.org Git - poi.git/commitdiff
[bug-65939] add partial fix for clearing formula with circular ref
authorPJ Fanning <fanningpj@apache.org>
Mon, 7 Mar 2022 13:11:23 +0000 (13:11 +0000)
committerPJ Fanning <fanningpj@apache.org>
Mon, 7 Mar 2022 13:11:23 +0000 (13:11 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1898680 13f79535-47bb-0310-9956-ffa450edef68

poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFCell.java
poi/src/test/java/org/apache/poi/ss/formula/TestFormulaEval.java

index f16a81202ba229c106e4db5c11f1220628af863a..8e64af4487128a62a4040ef25c61af4f2cc6a96e 100644 (file)
@@ -604,7 +604,11 @@ public class HSSFCell extends CellBase {
             case ERROR:
                 byte errorValue = (byte) ((FormulaRecordAggregate)_record).getFormulaRecord().getCachedErrorValue();
                 _record = new BoolErrRecord();
-                ((BoolErrRecord)_record).setValue(errorValue);
+                try {
+                    ((BoolErrRecord)_record).setValue(errorValue);
+                } catch (IllegalArgumentException ise) {
+                    ((BoolErrRecord)_record).setValue((byte) ErrorEval.REF_INVALID.getErrorCode());
+                }
                 _cellType = CellType.ERROR;
                 break;
             default:
index 24e727b7c2e423d0eabeec1d9a301590c14c8ce5..3f2a43d76ea4c21dd25ed5c7a57bfc5939c39faa 100644 (file)
@@ -25,7 +25,6 @@ import org.apache.poi.hssf.usermodel.HSSFRow;
 import org.apache.poi.hssf.usermodel.HSSFSheet;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.ss.usermodel.CellType;
-import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
 
 import java.io.IOException;
@@ -34,7 +33,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
 
 class TestFormulaEval {
 
-    @Disabled("https://bz.apache.org/bugzilla/show_bug.cgi?id=65939")
     @Test
     void testCircularRef() throws IOException {
         try (HSSFWorkbook wb = new HSSFWorkbook()) {
@@ -46,8 +44,10 @@ class TestFormulaEval {
             // the following assert should probably be NUMERIC not ERROR (from testing in Excel itself)
             assertEquals(CellType.ERROR, formulaEvaluator.evaluateFormulaCell(cell));
 
-            cell.setCellFormula(null); //this line fails
+            cell.setCellFormula(null);
             formulaEvaluator.notifyUpdateCell(cell);
+            //the following assert should probably be BLANK not ERROR
+            assertEquals(CellType.ERROR, cell.getCellType());
         }
     }
 }