Bug 55032

Summary: if a formula contains optional argument, it throws a runtime exception
Product: POI Reporter: hawkchen
Component: XSSFAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: normal CC: hawkchen
Priority: P2    
Version: 3.8-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: All   

Description hawkchen 2013-05-31 07:46:19 UTC
Problem Description:

if you enter a formula like
=PV(0.08/12, 20*12, 500, ,0)

Notice the 4th argument is missing. In this case, 4th and 5th arguments are both optional.


Actual:
it throws java.lang.RuntimeException: Unexpected arg eval type (org.apache.poi.ss.formula.eval.MissingArgEval)


Expected:
It seems it cannot accept an optional argument in the middle of argument list. But Excel can accept and treat the omitted arguments as 0.
Comment 1 hawkchen 2013-05-31 08:13:14 UTC
Suggested solution:
in
public abstract class FinanceFunction implements Function3Arg, Function4Arg {
...
	public ValueEval evaluate(ValueEval[] args, int srcRowIndex, int srcColumnIndex) {
		switch (args.length) {
			case 3:
				return evaluate(srcRowIndex, srcColumnIndex, args[0], args[1], args[2], DEFAULT_ARG3, DEFAULT_ARG4);
			case 4:
				return evaluate(srcRowIndex, srcColumnIndex, args[0], args[1], args[2], args[3], DEFAULT_ARG4);
			case 5:
				return evaluate(srcRowIndex, srcColumnIndex, args[0], args[1], args[2], args[3], args[4]);
		}
		return ErrorEval.VALUE_INVALID;
	}

Convert MissArgEval to DEFAULT_ARG3 or DEFAULT_ARG4 in case 4 and case 5.
Comment 2 Dominik Stadler 2015-10-01 14:06:21 UTC
This should be fixed in trunk via r1706254 now.