Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
3.1
-
None
Description
The following test case with AIOOB.
@Test public void testEmptyBody() throws Exception { JexlScript e = JEXL.createScript("var i = 0; do ; while((i+=1) < 10); i"); JexlContext jc = new MapContext(); Object o = e.execute(jc); Assert.assertEquals(10, o); }
The suggestion is to change interpreter as follows
@Override protected Object visit(ASTDoWhileStatement node, Object data) { Object result = null; /* last objectNode is the expression */ Node expressionNode = node.jjtGetChild(node.jjtGetNumChildren()-1); do { cancelCheck(node); if (node.jjtGetNumChildren() > 1) { try { // execute statement result = node.jjtGetChild(0).jjtAccept(this, data); } catch (JexlException.Break stmtBreak) { break; } catch (JexlException.Continue stmtContinue) { //continue; } } } while (arithmetic.toBoolean(expressionNode.jjtAccept(this, data))); return result; }
and Debugger as follows
@Override protected Object visit(ASTDoWhileStatement node, Object data) { int num = node.jjtGetNumChildren(); builder.append("do "); if (num > 1) { acceptStatement(node.jjtGetChild(0), data); } else { builder.append(" ; "); } builder.append(" while ("); accept(node.jjtGetChild(num - 1), data); builder.append(")"); return data; }