null variables

76 views
Skip to first unread message

Trevor

unread,
Feb 1, 2010, 5:06:33 AM2/1/10
to Jep Java Users
Hello,

We are having the same problem described here

http://groups.google.com/group/jep-users/browse_thread/thread/8934dc53031545a6#

We want to be able to evaluate an expression like this

if(IsNull(x), y, x)

but jep throws an exception if x is null. If we set
FastEvaluator.setTrapNullValues(false) then we get an exception in the
standard functions (even though we aren't using them in our
expression)

com.singularsys.jep.functions.IllegalParameterException: *: lllegal
parameters null, 1000.0(Double)
at com.singularsys.jep.functions.Multiply.mul(Unknown Source)
at com.singularsys.jep.functions.Multiply.eval(Unknown Source)
at com.singularsys.jep.standard.FastEvaluator.visitFun(Unknown
Source)
at com.singularsys.jep.standard.FastEvaluator.nodeAccept(Unknown
Source)
at com.singularsys.jep.standard.FastEvaluator.evaluate(Unknown
Source)
at com.singularsys.jep.Jep.evaluate(Unknown Source)
at com.singularsys.jep.Jep.evaluateD(Unknown Source)

Is there a way to do this?

Thanks,

Trevor

Rich Morris

unread,
Feb 3, 2010, 4:01:50 AM2/3/10
to Jep Java Users
Whats the expression you are supplying to evaluateD?

It looks like you are evaluating some equation multiplying a variable
by 1000, the variables looks like it has a null value. I'd need a few
more details to see whats going on.

Rich

On Feb 1, 10:06 am, Trevor <trevordkra...@gmail.com> wrote:
> Hello,
>
> We are having the same problem described here
>

> http://groups.google.com/group/jep-users/browse_thread/thread/8934dc5...

Trevor

unread,
Feb 10, 2010, 8:02:27 AM2/10/10
to Jep Java Users
if(isNull(x), y, x)

Note that this error is only throw when calling jep.evaluateD().

Trevor

Nathan Funk

unread,
Mar 10, 2010, 11:14:35 AM3/10/10
to Jep Java Users
Just in case you haven't resolved this issue yet, what was happening
is that the parser does not find the IsNull method in the function
table (it is not included by default), so it interprets IsNull as a
variable (since the AllowUndeclaredVariables option is on by default).
And because the ImplicitMultiplication option is also on by default,
IsNull(x) is parsed as IsNull*(x) or IsNull*x. Finally, during
evaluation multiplying by null causes an exception to be thrown.

The solution is to add IsNull to the function table with
jep.addFunction("isNull", new IsNull());

You may also want to turn off allowing undeclared variables and
implicit multiplication if you do not use them.

Hope this is helpful,

Nathan Funk

Reply all
Reply to author
Forward
0 new messages