Bug 55032 - if a formula contains optional argument, it throws a runtime exception
Summary: if a formula contains optional argument, it throws a runtime exception
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 3.8-FINAL
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-05-31 07:46 UTC by hawkchen
Modified: 2015-10-01 14:06 UTC (History)
1 user (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.