com.singularsys.jep.EvaluationException: Stack corrupted

26 views
Skip to first unread message

gattin...@googlemail.com

unread,
Dec 18, 2017, 9:59:26 AM12/18/17
to Jep Java Users
Dear support,

we encounter a problem that sometimes the evaluation of a formula fails an EvaluationException complaining about a corrupted stack:

    [...application specific stack trace...]
 at com.singularsys.jep.standard.FastEvaluator.visitVar(Unknown Source) at com.singularsys.jep.standard.FastEvaluator.nodeAccept(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.evaluate(Unknown Source) ... 84 more Caused by: com.singularsys.jep.EvaluationException: Stack corrupted at com.singularsys.jep.standard.FastEvaluator.evaluate(Unknown Source) at com.singularsys.jep.Jep.evaluate(Unknown Source) at com.singularsys.jep.Jep.evaluate(Unknown Source)

The strange thing about it is, that it seems the formula is correctly evaluated in most cases.
So what might be the reason why the exception occurs, i. e. what can make the stack to be corrupted during evaluation?

Thank you in advance for helping me.

Kind regards,
Marcus

Richard Morris

unread,
Dec 18, 2017, 5:21:25 PM12/18/17
to Jep Java Users
A  Stack corrupted exception is raised when there are still items left on the stack after the expression is evaluated. 

Possible causes might be a PostfixMathCommand which is not taking the right number of items off the stack.

There can be a problem with the curNumberOfParameters field. A PostFixMathCommand's run() method must make sure to take the curNumberOfParameters off the stack, and push exactly one item back on. 

This should only impact on functions which don't implement any of the other function interfaces like BinaryFunction as these don't use the stack. 

I would need a bit more information to help debug further. Ideally, the full expression which is causing problems, or possibly the name of all the functions and operators called. 

Hope that helps

Richard

gattin...@googlemail.com

unread,
Dec 19, 2017, 4:01:56 AM12/19/17
to Jep Java Users
Thank you, Richard!

I'll try to gather more details on the formula and values causing the exception as soon as possible.

Marcus

Richard Morris

unread,
Dec 19, 2017, 4:34:16 AM12/19/17
to Jep Java Users
One thing which could be done is check the stack during each call to 

com.singularsys.jep.standard.FastEvaluator.visitFun(Node)

have a line at the beginning of the method

int curStackSize = this.stack.size();

and one at the end of the method

        if( this.stack.size() !=curStackSize )
           
throw new EvaluationException("Stack missmatch in evaluating function "+node.getName());
       
return res;

this would give a finer level check and should identify where the problem happens.

Richard

Reply all
Reply to author
Forward
0 new messages