aboutsummaryrefslogtreecommitdiffstats
path: root/poi
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2022-03-07 13:11:23 +0000
committerPJ Fanning <fanningpj@apache.org>2022-03-07 13:11:23 +0000
commit3a496fded841b403138cec194280fc1f3ac43a66 (patch)
tree60729071570b5f84e3642a01b95a81b2232e8426 /poi
parent3317b6393f214e274009a820300dc6b1a84bde9c (diff)
downloadpoi-3a496fded841b403138cec194280fc1f3ac43a66.tar.gz
poi-3a496fded841b403138cec194280fc1f3ac43a66.zip
[bug-65939] add partial fix for clearing formula with circular ref
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1898680 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi')
-rw-r--r--poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFCell.java6
-rw-r--r--poi/src/test/java/org/apache/poi/ss/formula/TestFormulaEval.java6
2 files changed, 8 insertions, 4 deletions
diff --git a/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFCell.java b/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFCell.java
index f16a81202b..8e64af4487 100644
--- a/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFCell.java
+++ b/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFCell.java
@@ -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:
diff --git a/poi/src/test/java/org/apache/poi/ss/formula/TestFormulaEval.java b/poi/src/test/java/org/apache/poi/ss/formula/TestFormulaEval.java
index 24e727b7c2..3f2a43d76e 100644
--- a/poi/src/test/java/org/apache/poi/ss/formula/TestFormulaEval.java
+++ b/poi/src/test/java/org/apache/poi/ss/formula/TestFormulaEval.java
@@ -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());
}
}
}