Sidebar

What causes a java.lang.StackOverflowError?

0 votes
840 views
asked Mar 20, 2018 by ron-s-6919 (4,480 points)
I am getting an error that causes my message to be sent to the Error Queue.  The error message is:
java.lang.StackOverflowError
   at org.mozilla.javascript.IRFactory.transform(IRFactory.java:161)
   at org.mozilla.javascript.IRFactory.transformInfix(IRFactory.java:752)
   at org.mozilla.javascript.IRFactory.transform(IRFactory.java:161)
   at org.mozilla.javascript.IRFactory.transformInfix(IRFactory.java:752)
   . . . .

1 Answer

0 votes

This exception can be thrown in many ways.  Usually it is while using the javascript eval() function.  Here is an example of causing this StackOvervlowError to be thrown:

var equation = "9";
for (var i = 0; i<10000; i++) {
   equation += "*9";
}

var result = eval(equation);

Executing this script in the QIE test window will result in the test window hanging.  When the qie.log file is reviewewed, the StackOverflowError will be found.  Starting this channel and processing a message will cause the message to go to the error queue with the same StackOverflowError.

As a general rule, the eval() function should be avoided and the script re-written to accomplish the same thing without needing the eval().  For example, the above script could be re-written to do the math on each iteration instead of building a large string to execute the eval() statement on.

var result = 9;
for (var i = 0; i<10000; i++) {
   result = result * 9;
}

qie.debug(result);

answered Mar 21, 2018 by ben-s-7515 (12,640 points)
...