Bug 65939 - StackOverflow on notifyUpdateCell
Summary: StackOverflow on notifyUpdateCell
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 5.2.0-FINAL
Hardware: PC All
: P2 major (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-03-07 11:29 UTC by Cédric O
Modified: 2022-03-12 10:07 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Cédric O 2022-03-07 11:29:54 UTC
A java.lang.StackOverflowError occurs on the method org.apache.poi.ss.formula.CellCacheEntry.recurseClearCachedFormulaResults in the following condition :
- Create a circular reference on the cell itself (e.g. A1 on cell A1).
- Remove the formula
- Call the notifyUpdateCell method.

Below, a sample code, tested on version 5.2.1, Java 17. :

public static void main(String[] args) {
	try (var workbook = new XSSFWorkbook()) {
		var sheet = workbook.createSheet();
		var row = sheet.createRow(0);
		var cell = row.createCell(0);
		cell.setCellFormula("A1");
		var formulaEvaluator = workbook.getCreationHelper().createFormulaEvaluator();
		formulaEvaluator.notifyUpdateCell(cell);
		formulaEvaluator.evaluateAll();

		System.out.println(FormulaError.forInt(cell.getErrorCellValue()));

		cell.setCellFormula(null);
		formulaEvaluator.notifyUpdateCell(cell);

	} catch (IOException e) {
		e.printStackTrace();
	}
}
Comment 1 PJ Fanning 2022-03-07 11:43:12 UTC
In my online copy of Excel, I set the value of cell A1 to `=A1` and was surprised to find it evaluate to `0` as opposed to a #REF error.

Would you like to try to submit your own patch?
Comment 2 PJ Fanning 2022-03-07 12:07:19 UTC
I added r1898677 but I think there is a fair amount more work to be done.
Comment 3 Cédric O 2022-03-07 12:24:38 UTC
(In reply to PJ Fanning from comment #1)
> In my online copy of Excel, I set the value of cell A1 to `=A1` and was
> surprised to find it evaluate to `0` as opposed to a #REF error.
> 
> Would you like to try to submit your own patch?

I also get 0 in the MS Excel cell, but in the bottom left of the app, it still shows a circular reference error on cell A1.
Comment 4 Cédric O 2022-03-07 12:27:15 UTC
(In reply to PJ Fanning from comment #2)
> I added r1898677 but I think there is a fair amount more work to be done.

Ok nice, what kind of work needs to be done in your opinion regarding this issue ?
Comment 5 PJ Fanning 2022-03-07 13:05:39 UTC
* there are misbehaviours commented out or disabled in the new tests I added
* there are other scenarios to test - like A1 set to `=A2` and A2 set to = `A1`
Comment 6 PJ Fanning 2022-03-07 13:16:51 UTC
I added some extra test coverage and things seem ok - could certainly do with more testing but the initial test scenario seems to be fixed