View | Details | Raw Unified | Return to bug 44413
Collapse All | Expand All

(-)src/scratchpad/src/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java (-9 / +17 lines)
Lines 96-103 Link Here
96
/**
96
/**
97
 * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
97
 * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
98
 * 
98
 * 
99
 * Limitations: Unfortunately, cyclic references will cause stackoverflow
100
 * exception
101
 */
99
 */
102
public class HSSFFormulaEvaluator {
100
public class HSSFFormulaEvaluator {
103
                
101
                
Lines 348-363 Link Here
348
     * Dev. Note: Internal evaluate must be passed only a formula cell 
346
     * Dev. Note: Internal evaluate must be passed only a formula cell 
349
     * else a runtime exception will be thrown somewhere inside the method.
347
     * else a runtime exception will be thrown somewhere inside the method.
350
     * (Hence this is a private method.)
348
     * (Hence this is a private method.)
351
     * 
352
     * @param srcCell
353
     * @param srcRow
354
     * @param sheet
355
     * @param workbook
356
     */
349
     */
357
    protected static ValueEval internalEvaluate(HSSFCell srcCell, HSSFRow srcRow, HSSFSheet sheet, HSSFWorkbook workbook) {
350
    private static ValueEval internalEvaluate(HSSFCell srcCell, HSSFRow srcRow, HSSFSheet sheet, HSSFWorkbook workbook) {
358
        int srcRowNum = srcRow.getRowNum();
351
        int srcRowNum = srcRow.getRowNum();
359
        short srcColNum = srcCell.getCellNum();
352
        short srcColNum = srcCell.getCellNum();
360
        FormulaParser parser = new FormulaParser(srcCell.getCellFormula(), workbook.getWorkbook());
353
        
354
        
355
        EvaluationCycleDetector tracker = EvaluationCycleDetectorManager.getTracker();
356
        
357
        if(!tracker.startEvaluate(workbook, sheet, srcRowNum, srcColNum)) {
358
        	return ErrorEval.CIRCULAR_REF_ERROR;
359
        }
360
        try {
361
        	return evaluateCell(workbook, sheet, srcRowNum, srcColNum, srcCell.getCellFormula());
362
        } finally {
363
        	tracker.endEvaluate(workbook, sheet, srcRowNum, srcColNum);
364
        }
365
    }
366
    private static ValueEval evaluateCell(HSSFWorkbook workbook, HSSFSheet sheet, 
367
    		int srcRowNum, short srcColNum, String cellFormulaText) {
368
        FormulaParser parser = new FormulaParser(cellFormulaText, workbook.getWorkbook());
361
        parser.parse();
369
        parser.parse();
362
        Ptg[] ptgs = parser.getRPNPtg();
370
        Ptg[] ptgs = parser.getRPNPtg();
363
        // -- parsing over --
371
        // -- parsing over --

Return to bug 44413