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

            Bug ID: 58975
           Summary: Function update fails on functions with more than 127
                    arguments
           Product: POI
           Version: 3.13-FINAL
          Hardware: PC
            Status: NEW
          Severity: normal
          Priority: P2
         Component: XSSF
          Assignee: [email protected]
          Reporter: [email protected]

I recently encountered a problem when trying to rename a sheet.

Exception in thread "main" java.lang.NegativeArraySizeException
    at
org.apache.poi.ss.formula.FormulaRenderer.getOperands(FormulaRenderer.java:118)
    at
org.apache.poi.ss.formula.FormulaRenderer.toFormulaString(FormulaRenderer.java:100)
    at
org.apache.poi.xssf.usermodel.helpers.XSSFFormulaUtils.updateFormula(XSSFFormulaUtils.java:101)
    at
org.apache.poi.xssf.usermodel.helpers.XSSFFormulaUtils.updateSheetName(XSSFFormulaUtils.java:79)
    at
org.apache.poi.xssf.usermodel.XSSFWorkbook.setSheetName(XSSFWorkbook.java:1571)

After some poking around, I found that that the issue is that one of the cells
previously added had 176 arguments in a CONCATENATE function (don't ask...)
which was causing the byte value of _numberOfArgs in
org.apache.poi.ss.formula.ptg.AbstractFunctionPtg to overflow. Excel does not
actually limit the number of arguments in CONCATENATE itself, and the sheet
works fine in POI unless you try to parse the formula. Unfortunately, renaming
a sheet parses all function cells to see if they need to be renamed. A very
similar cell with 108 arguments does not cause this issue.

A workaround for anyone encountering this bug is to simply turn any call to
CONCATENATE(1,2,...,x) to CONCATENATE(1,2,...125,CONCATENATE(125,126,....x)),
repeating this split as many times as required. This causes the function to
parse properly and returns the same result.

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to