Bug 49841 - LEFT and RIGHT text functions throw a StringIndexOutOfBoundsException when called with a negative operand
Summary: LEFT and RIGHT text functions throw a StringIndexOutOfBoundsException when ca...
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.7-dev
Hardware: PC All
: P2 major (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-08-29 16:04 UTC by Brendan Nolan
Modified: 2010-09-04 05:48 UTC (History)
0 users



Attachments
Patch containing fix and test case (3.50 KB, patch)
2010-08-29 16:11 UTC, Brendan Nolan
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Brendan Nolan 2010-08-29 16:04:45 UTC
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);
Comment 1 Brendan Nolan 2010-08-29 16:11:33 UTC
Created attachment 25959 [details]
Patch containing fix and test case
Comment 2 Yegor Kozlov 2010-09-04 05:48:59 UTC
Applied in r992570

Thanks,
Yegor