You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Henri Biestro (Jira)" <ji...@apache.org> on 2021/06/07 13:15:06 UTC
[jira] [Closed] (JEXL-321) Empty do-while loop is broken
[ https://issues.apache.org/jira/browse/JEXL-321?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Henri Biestro closed JEXL-321.
------------------------------
> Empty do-while loop is broken
> -----------------------------
>
> Key: JEXL-321
> URL: https://issues.apache.org/jira/browse/JEXL-321
> Project: Commons JEXL
> Issue Type: Bug
> Affects Versions: 3.1
> Reporter: Dmitri Blinov
> Priority: Major
> Fix For: 3.2
>
>
> The following test case with AIOOB.
> {code:java}
> @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);
> } {code}
> The suggestion is to change interpreter as follows
> {code}
> @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;
> }
> {code} and Debugger as follows
> {code}
> @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;
> }
> {code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)