[ 
https://issues.apache.org/jira/browse/JEXL-204?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15377236#comment-15377236
 ] 

Dmitri Blinov commented on JEXL-204:
------------------------------------

I can't figure out what is the logic behind current implementation of script 
interruptablity/error handling.

For example the following script will execute up to the end and return 42 in 
any mode (strict/silent)

{code}
x = null.1; return 42
{code}

whereas the following script will break with exception "bean is null" also in 
any mode (strict/silent)

{code}
null.1 = 2; return 42
{code}

and the following script will throw an exception in strict mode regardless of 
being silent/non-silent
{code}
z = [1,2]; x = z[3]; return 42
{code}

The documentation states that
{quote}
The strict flag tells the engine when and if null as operand is considered an 
error, the silent flag tells the engine what to do with the error (log as 
warning or throw exception)
{quote}

>From the first example we see that null is not considered as error when we 
>resolve bean property value, even does not log a message, while it might be 
>expected in strict mode. From the second example we see that null is always 
>considered as an error when we set bean property value, but is never ignored 
>(always breaks script execution), even in silent mode. From the third example 
>we see that AIOOBE is also considered as an error that breaks script execution 
>in strict mode, regardless of silent/non-silent mode.

> Script is not interrupted by a method call throwing Exception
> -------------------------------------------------------------
>
>                 Key: JEXL-204
>                 URL: https://issues.apache.org/jira/browse/JEXL-204
>             Project: Commons JEXL
>          Issue Type: Bug
>    Affects Versions: 3.0
>            Reporter: Dmitri Blinov
>            Assignee: Henri Biestro
>             Fix For: 3.0.1
>
>
> The following test case fails with the message 
> {quote}
> java.lang.AssertionError: should have thrown a Cancel
>         at org.junit.Assert.fail(Assert.java:88)
>         at 
> org.apache.commons.jexl3.ScriptInterruptableTest.testExceptionCancellable(ScriptInterruptableTest.java:73)
> {quote}
> {code}
> @SuppressWarnings({"UnnecessaryBoxing", 
> "AssertEqualsBetweenInconvertibleTypes"})
> public class ScriptInterruptableTest extends JexlTestCase {
>     //Logger LOGGER = Logger.getLogger(VarTest.class.getName());
>     public ScriptInterruptableTest() {
>         super("ScriptInterruptableTest");
>     }
>     public static class DummyInterrupt {
>         public int except() throws Exception {
>            throw new Exception("Cancelled by purpose");
>         }
>     }
>     public static class TestContext extends MapContext implements 
> JexlContext.NamespaceResolver {
>         @Override
>         public Object resolveNamespace(String name) {
>             return name == null ? this : null;
>         }
>     }
>     @Test
>     public void testExceptionCancellable() throws Exception {
>         JexlEngine jexl = new 
> JexlBuilder().silent(true).strict(false).cancellable(true).create();
>         JexlContext ctxt = new TestContext();
>         ctxt.set("x", new DummyInterrupt());
>         // run an interrupt
>         JexlScript sint = jexl.createScript("x.except(); return 42");
>         Object t = null;
>         Script.Callable c = (Script.Callable) sint.callable(ctxt);
>         try {
>             t = c.call();
>             if (c.isCancellable()) {
>                 Assert.fail("should have thrown a Cancel");
>             }
>         } catch (JexlException.Cancel xjexl) {
>             if (!c.isCancellable()) {
>                 Assert.fail("should not have thrown " + xjexl);
>             }
>         }
>         Assert.assertTrue(c.isCancelled());
>         Assert.assertNotEquals(42, t);
>     }
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to