https://bz.apache.org/bugzilla/show_bug.cgi?id=61116

            Bug ID: 61116
           Summary: Formula evaluation fails when using matrix addition
                    within index function call with RuntimeException
           Product: POI
           Version: 3.16-FINAL
          Hardware: PC
            Status: NEW
          Severity: normal
          Priority: P2
         Component: XSSF
          Assignee: dev@poi.apache.org
          Reporter: sn...@web.de
  Target Milestone: ---

Created attachment 35003
  --> https://bz.apache.org/bugzilla/attachment.cgi?id=35003&action=edit
Example workbook showing the problematic formulas

The formula evaluation fails when using following formula:
  "=INDEX(A+B,1,1)"
where A and B are both matrices. I've attached an example workbook that shows
the problem (matrix-addition-within-index-function.xlsx). Simply use the
FormulaEvaluator to evaluate the cell 'sample2'!B2 and you will get the
following exception:

"java.lang.RuntimeException: Incomplete code - cannot handle first arg of type
(org.apache.poi.ss.formula.eval.NumberEval)
        at
org.apache.poi.ss.formula.functions.Index.convertFirstArg(Index.java:106)
        at org.apache.poi.ss.formula.functions.Index.evaluate(Index.java:75)
        at org.apache.poi.ss.formula.functions.Index.evaluate(Index.java:116)
        at
org.apache.poi.ss.formula.OperationEvaluatorFactory.evaluate(OperationEvaluatorFactory.java:132)
        at
org.apache.poi.ss.formula.WorkbookEvaluator.evaluateFormula(WorkbookEvaluator.java:550)
        at
org.apache.poi.ss.formula.WorkbookEvaluator.evaluateAny(WorkbookEvaluator.java:317)
        at
org.apache.poi.ss.formula.WorkbookEvaluator.evaluateReference(WorkbookEvaluator.java:750)
        at
org.apache.poi.ss.formula.SheetRefEvaluator.getEvalForCell(SheetRefEvaluator.java:48)"

The currently implementation assumes that the maxtrix addition always returns a
single double value which is fine for maxtrix formulas like "=A+B". In this
case it does the same and so "A+B" is evaluated to a sum of single values from
each matrix. As soon this resulting double value is passed to the index
function it will fail with the exception.

How to fix?
I guess the method TwoOperandNumericOperation.evaluate(int, int, ValueEval,
ValueEval) need to distiguish whether the expected output of the operation
(affects not only AddPtg) is a single value or still an area.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@poi.apache.org
For additional commands, e-mail: dev-h...@poi.apache.org

Reply via email to