https://issues.apache.org/bugzilla/show_bug.cgi?id=49841

           Summary: LEFT and RIGHT text functions throw a
                    StringIndexOutOfBoundsException when called with a
                    negative operand
           Product: POI
           Version: 3.7-dev
          Platform: PC
            Status: NEW
          Severity: major
          Priority: P2
         Component: HSSF
        AssignedTo: [email protected]
        ReportedBy: [email protected]


LEFT("ANYSTRING", -1)
RIGHT("ANYSTRING", -1)

Either of the functions above should return #VALUE! but return an exception

Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String
index out of range: -1
    at java.lang.String.substring(String.java:1937)
    at
org.apache.poi.hssf.record.formula.functions.TextFunction$LeftRight.evaluate(TextFunction.java:183)
    at
org.apache.poi.hssf.record.formula.functions.Var1or2ArgFunction.evaluate(Var1or2ArgFunction.java:36)
    at
org.apache.poi.ss.formula.OperationEvaluatorFactory.evaluate(OperationEvaluatorFactory.java:132)


HSSFWorkbook wbHSSF = new HSSFWorkbook();
HSSFSheet sheetHSSF = wbHSSF.createSheet("LEFTRIGHTTESTSHEET");
FormulaEvaluator createFormulaEvaluator =
wbHSSF.getCreationHelper().createFormulaEvaluator();
HSSFCell createCell =
sheetHSSF.createRow(0).createCell(0,Cell.CELL_TYPE_FORMULA);
createCell.setCellFormula("LEFT(\"ANYSTRING\",-1)");        
createFormulaEvaluator.evaluate(createCell);

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- 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