[jira] [Commented] (JEXL-193) InterruptedException is swallowed in function call in silent and non-strict mode

2016-05-06 Thread Dmitri Blinov (JIRA)

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

Dmitri Blinov commented on JEXL-193:


I think correct test case should be this

{code}
   public static class TestContext extends MapContext implements 
JexlContext.NamespaceResolver {

public int interrupt() throws InterruptedException {
throw new InterruptedException();
}
}

@Test
public void testInterrupt() throws Exception {
JexlEngine jexl = new JexlBuilder().arithmetic(new 
JexlArithmetic(false)).strict(false).silent(true).create();
JexlScript e = jexl.createScript("interrupt(); return 42");
Callable c = e.callable(new TestContext());
try {
   Object t = c.call();
   Assert.fail("Should have thrown JexlException.Cancel");
} catch (JexlException.Cancel je) {
   // Fine
}
}
{code}

> InterruptedException is swallowed in function call in silent and non-strict 
> mode
> 
>
> Key: JEXL-193
> URL: https://issues.apache.org/jira/browse/JEXL-193
> 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 
> {code}
> java.lang.AssertionError: Values should be different. Actual: 42
>   at org.junit.Assert.fail(Assert.java:88)
>   at org.junit.Assert.failEquals(Assert.java:185)
>   at org.junit.Assert.assertNotEquals(Assert.java:161)
> {code}
> {code}
> public static class TestContext extends MapContext implements 
> JexlContext.NamespaceResolver {
> public int interrupt() throws InterruptedException {
> throw new InterruptedException();
> }
> }
> @Test
> public void testInterrupt() throws Exception {
> JexlEngine jexl = new JexlBuilder().arithmetic(new 
> JexlArithmetic(false)).strict(false).silent(true).create();
> JexlScript e = jexl.createScript("interrupt(); return 42");
> Callable c = e.callable(new TestContext());
> Object t = c.call();
> Assert.assertNotEquals(42, t);
> }
> {code}
> Expected behaviour is to cancel script execution



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


[jira] [Commented] (JEXL-193) InterruptedException is swallowed in function call in silent and non-strict mode

2016-05-06 Thread Henri Biestro (JIRA)

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

Henri Biestro commented on JEXL-193:


Jexl will break current script execution, the callable call method will return 
null, the thread returned to the executor pool in the examples or ready to be 
joined (i.e. thread has stopped).

> InterruptedException is swallowed in function call in silent and non-strict 
> mode
> 
>
> Key: JEXL-193
> URL: https://issues.apache.org/jira/browse/JEXL-193
> 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 
> {code}
> java.lang.AssertionError: Values should be different. Actual: 42
>   at org.junit.Assert.fail(Assert.java:88)
>   at org.junit.Assert.failEquals(Assert.java:185)
>   at org.junit.Assert.assertNotEquals(Assert.java:161)
> {code}
> {code}
> public static class TestContext extends MapContext implements 
> JexlContext.NamespaceResolver {
> public int interrupt() throws InterruptedException {
> throw new InterruptedException();
> }
> }
> @Test
> public void testInterrupt() throws Exception {
> JexlEngine jexl = new JexlBuilder().arithmetic(new 
> JexlArithmetic(false)).strict(false).silent(true).create();
> JexlScript e = jexl.createScript("interrupt(); return 42");
> Callable c = e.callable(new TestContext());
> Object t = c.call();
> Assert.assertNotEquals(42, t);
> }
> {code}
> Expected behaviour is to cancel script execution



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


[jira] [Commented] (JEXL-193) InterruptedException is swallowed in function call in silent and non-strict mode

2016-05-06 Thread Dmitri Blinov (JIRA)

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

Dmitri Blinov commented on JEXL-193:


Future.cancel(true) will *attempt* to stop the task by invoking 
Thread.interrupt() for executing thread. Whether the executing thread will stop 
or not depends on how it is implemented. Jexl will check that thread is 
interrupted, break current script execution, but if in silent mode, will clear 
thread's interrupted state and return null. So the thread *will not* stop. If 
jexl is in non-silent mode, it will clear thread's interrupted state but throw 
Cancel exception. I can catch Cancel exception and re-throw 
InterruptedException instead and the thread eventually *will* stop. What I'm 
trying to propose is that jexl should throw Cancel exception regardless of its 
mode, silent or non-silent, to let me know it was interrupted during execution.

> InterruptedException is swallowed in function call in silent and non-strict 
> mode
> 
>
> Key: JEXL-193
> URL: https://issues.apache.org/jira/browse/JEXL-193
> 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 
> {code}
> java.lang.AssertionError: Values should be different. Actual: 42
>   at org.junit.Assert.fail(Assert.java:88)
>   at org.junit.Assert.failEquals(Assert.java:185)
>   at org.junit.Assert.assertNotEquals(Assert.java:161)
> {code}
> {code}
> public static class TestContext extends MapContext implements 
> JexlContext.NamespaceResolver {
> public int interrupt() throws InterruptedException {
> throw new InterruptedException();
> }
> }
> @Test
> public void testInterrupt() throws Exception {
> JexlEngine jexl = new JexlBuilder().arithmetic(new 
> JexlArithmetic(false)).strict(false).silent(true).create();
> JexlScript e = jexl.createScript("interrupt(); return 42");
> Callable c = e.callable(new TestContext());
> Object t = c.call();
> Assert.assertNotEquals(42, t);
> }
> {code}
> Expected behaviour is to cancel script execution



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


[jira] [Commented] (JEXL-193) InterruptedException is swallowed in function call in silent and non-strict mode

2016-05-06 Thread Henri Biestro (JIRA)

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

Henri Biestro commented on JEXL-193:


Call future.cance(true) in the TimeoutException handling.

> InterruptedException is swallowed in function call in silent and non-strict 
> mode
> 
>
> Key: JEXL-193
> URL: https://issues.apache.org/jira/browse/JEXL-193
> 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 
> {code}
> java.lang.AssertionError: Values should be different. Actual: 42
>   at org.junit.Assert.fail(Assert.java:88)
>   at org.junit.Assert.failEquals(Assert.java:185)
>   at org.junit.Assert.assertNotEquals(Assert.java:161)
> {code}
> {code}
> public static class TestContext extends MapContext implements 
> JexlContext.NamespaceResolver {
> public int interrupt() throws InterruptedException {
> throw new InterruptedException();
> }
> }
> @Test
> public void testInterrupt() throws Exception {
> JexlEngine jexl = new JexlBuilder().arithmetic(new 
> JexlArithmetic(false)).strict(false).silent(true).create();
> JexlScript e = jexl.createScript("interrupt(); return 42");
> Callable c = e.callable(new TestContext());
> Object t = c.call();
> Assert.assertNotEquals(42, t);
> }
> {code}
> Expected behaviour is to cancel script execution



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


[jira] [Commented] (JEXL-193) InterruptedException is swallowed in function call in silent and non-strict mode

2016-05-06 Thread Dmitri Blinov (JIRA)

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

Dmitri Blinov commented on JEXL-193:


As I understand that will be only one part of the solution. From the point of 
monitoring thread I will know the executing thread has timed out, the problem 
is that will just not prevent the executing thread from continuing. 

> InterruptedException is swallowed in function call in silent and non-strict 
> mode
> 
>
> Key: JEXL-193
> URL: https://issues.apache.org/jira/browse/JEXL-193
> 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 
> {code}
> java.lang.AssertionError: Values should be different. Actual: 42
>   at org.junit.Assert.fail(Assert.java:88)
>   at org.junit.Assert.failEquals(Assert.java:185)
>   at org.junit.Assert.assertNotEquals(Assert.java:161)
> {code}
> {code}
> public static class TestContext extends MapContext implements 
> JexlContext.NamespaceResolver {
> public int interrupt() throws InterruptedException {
> throw new InterruptedException();
> }
> }
> @Test
> public void testInterrupt() throws Exception {
> JexlEngine jexl = new JexlBuilder().arithmetic(new 
> JexlArithmetic(false)).strict(false).silent(true).create();
> JexlScript e = jexl.createScript("interrupt(); return 42");
> Callable c = e.callable(new TestContext());
> Object t = c.call();
> Assert.assertNotEquals(42, t);
> }
> {code}
> Expected behaviour is to cancel script execution



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


[jira] [Commented] (JEXL-193) InterruptedException is swallowed in function call in silent and non-strict mode

2016-05-06 Thread Henri Biestro (JIRA)

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

Henri Biestro commented on JEXL-193:


Use a Future and a call get with a timeout to implement this behavior and 
everything is taken care of; you receive a TimeoutException if it took too 
long. Look at tests in ScriptCallableTest for some examples.

> InterruptedException is swallowed in function call in silent and non-strict 
> mode
> 
>
> Key: JEXL-193
> URL: https://issues.apache.org/jira/browse/JEXL-193
> 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 
> {code}
> java.lang.AssertionError: Values should be different. Actual: 42
>   at org.junit.Assert.fail(Assert.java:88)
>   at org.junit.Assert.failEquals(Assert.java:185)
>   at org.junit.Assert.assertNotEquals(Assert.java:161)
> {code}
> {code}
> public static class TestContext extends MapContext implements 
> JexlContext.NamespaceResolver {
> public int interrupt() throws InterruptedException {
> throw new InterruptedException();
> }
> }
> @Test
> public void testInterrupt() throws Exception {
> JexlEngine jexl = new JexlBuilder().arithmetic(new 
> JexlArithmetic(false)).strict(false).silent(true).create();
> JexlScript e = jexl.createScript("interrupt(); return 42");
> Callable c = e.callable(new TestContext());
> Object t = c.call();
> Assert.assertNotEquals(42, t);
> }
> {code}
> Expected behaviour is to cancel script execution



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


[jira] [Commented] (JEXL-193) InterruptedException is swallowed in function call in silent and non-strict mode

2016-05-06 Thread Dmitri Blinov (JIRA)

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

Dmitri Blinov commented on JEXL-193:


Suppose we have a multi-threaded system where each request is processed by some 
thread from the pool, and we have a policy for each request not to take longer 
when specified amount of time, and for requests that are not able to complete 
within the specified period we want those requests to be interrupted. That may 
be implemented by invoking Thread.interrupt() which by design should cancel all 
outstanding processing. If by chance the request is using jexl scripting when 
thread was interrupted, I expect jexl not only to break current script 
execution but somehow to notify me that the script processing has been ended 
unexpectedly, so I could decide how this should be handled, possibly rolling 
back pending transaction etc. As I see now from the code that exception is only 
thrown by in non-silent mode. If I chose to use non-silent mode to suit some 
other purposes, I'll never know that the thread was interrupted.

> InterruptedException is swallowed in function call in silent and non-strict 
> mode
> 
>
> Key: JEXL-193
> URL: https://issues.apache.org/jira/browse/JEXL-193
> 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 
> {code}
> java.lang.AssertionError: Values should be different. Actual: 42
>   at org.junit.Assert.fail(Assert.java:88)
>   at org.junit.Assert.failEquals(Assert.java:185)
>   at org.junit.Assert.assertNotEquals(Assert.java:161)
> {code}
> {code}
> public static class TestContext extends MapContext implements 
> JexlContext.NamespaceResolver {
> public int interrupt() throws InterruptedException {
> throw new InterruptedException();
> }
> }
> @Test
> public void testInterrupt() throws Exception {
> JexlEngine jexl = new JexlBuilder().arithmetic(new 
> JexlArithmetic(false)).strict(false).silent(true).create();
> JexlScript e = jexl.createScript("interrupt(); return 42");
> Callable c = e.callable(new TestContext());
> Object t = c.call();
> Assert.assertNotEquals(42, t);
> }
> {code}
> Expected behaviour is to cancel script execution



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


[jira] [Commented] (JEXL-193) InterruptedException is swallowed in function call in silent and non-strict mode

2016-05-06 Thread Henri Biestro (JIRA)

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

Henri Biestro commented on JEXL-193:


On checking cancellation when handling 'return';  if the return argument 
evaluation did not throw a cancel exception, we have a result and we were not 
interrupted. Not sure what we'd functionally gain by an extra check.
On the exception throwing when cancellation/interruption occur, do you have a 
use-case that suffers from the current behavior? Asynchronous/cancellable 
execution is best handled through Future<> which seemingly shield this detail.
OOM is an error you can (at least, will) not recover from, InterruptedException 
are (should be, at least in many useful scenarios) recoverable . 

> InterruptedException is swallowed in function call in silent and non-strict 
> mode
> 
>
> Key: JEXL-193
> URL: https://issues.apache.org/jira/browse/JEXL-193
> 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 
> {code}
> java.lang.AssertionError: Values should be different. Actual: 42
>   at org.junit.Assert.fail(Assert.java:88)
>   at org.junit.Assert.failEquals(Assert.java:185)
>   at org.junit.Assert.assertNotEquals(Assert.java:161)
> {code}
> {code}
> public static class TestContext extends MapContext implements 
> JexlContext.NamespaceResolver {
> public int interrupt() throws InterruptedException {
> throw new InterruptedException();
> }
> }
> @Test
> public void testInterrupt() throws Exception {
> JexlEngine jexl = new JexlBuilder().arithmetic(new 
> JexlArithmetic(false)).strict(false).silent(true).create();
> JexlScript e = jexl.createScript("interrupt(); return 42");
> Callable c = e.callable(new TestContext());
> Object t = c.call();
> Assert.assertNotEquals(42, t);
> }
> {code}
> Expected behaviour is to cancel script execution



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


[jira] [Commented] (JEXL-193) InterruptedException is swallowed in function call in silent and non-strict mode

2016-05-05 Thread Dmitri Blinov (JIRA)

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

Dmitri Blinov commented on JEXL-193:


BTW, I just have noticed that cancellation exception is still not thrown in 
Interpreter.interpret() in silent or non-strict mode. While I understand the 
conception
of silent execution I think exceptions like InterruptedException or 
OutOfMemoryError are kind of special (exceptional exceptions, he-he), and the 
invoking code should be informed no matter what mode jexl is configured with if 
such an exception was taken place 

> InterruptedException is swallowed in function call in silent and non-strict 
> mode
> 
>
> Key: JEXL-193
> URL: https://issues.apache.org/jira/browse/JEXL-193
> 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 
> {code}
> java.lang.AssertionError: Values should be different. Actual: 42
>   at org.junit.Assert.fail(Assert.java:88)
>   at org.junit.Assert.failEquals(Assert.java:185)
>   at org.junit.Assert.assertNotEquals(Assert.java:161)
> {code}
> {code}
> public static class TestContext extends MapContext implements 
> JexlContext.NamespaceResolver {
> public int interrupt() throws InterruptedException {
> throw new InterruptedException();
> }
> }
> @Test
> public void testInterrupt() throws Exception {
> JexlEngine jexl = new JexlBuilder().arithmetic(new 
> JexlArithmetic(false)).strict(false).silent(true).create();
> JexlScript e = jexl.createScript("interrupt(); return 42");
> Callable c = e.callable(new TestContext());
> Object t = c.call();
> Assert.assertNotEquals(42, t);
> }
> {code}
> Expected behaviour is to cancel script execution



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


[jira] [Commented] (JEXL-193) InterruptedException is swallowed in function call in silent and non-strict mode

2016-05-05 Thread Dmitri Blinov (JIRA)

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

Dmitri Blinov commented on JEXL-193:


I wonder should we also check for thread cancellation just before returning a 
value from script, so as to guarantee that if thread have been cancelled no 
value is returned by JEXL

> InterruptedException is swallowed in function call in silent and non-strict 
> mode
> 
>
> Key: JEXL-193
> URL: https://issues.apache.org/jira/browse/JEXL-193
> 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 
> {code}
> java.lang.AssertionError: Values should be different. Actual: 42
>   at org.junit.Assert.fail(Assert.java:88)
>   at org.junit.Assert.failEquals(Assert.java:185)
>   at org.junit.Assert.assertNotEquals(Assert.java:161)
> {code}
> {code}
> public static class TestContext extends MapContext implements 
> JexlContext.NamespaceResolver {
> public int interrupt() throws InterruptedException {
> throw new InterruptedException();
> }
> }
> @Test
> public void testInterrupt() throws Exception {
> JexlEngine jexl = new JexlBuilder().arithmetic(new 
> JexlArithmetic(false)).strict(false).silent(true).create();
> JexlScript e = jexl.createScript("interrupt(); return 42");
> Callable c = e.callable(new TestContext());
> Object t = c.call();
> Assert.assertNotEquals(42, t);
> }
> {code}
> Expected behaviour is to cancel script execution



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


[jira] [Commented] (JEXL-193) InterruptedException is swallowed in function call in silent and non-strict mode

2016-04-18 Thread Dmitri Blinov (JIRA)

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

Dmitri Blinov commented on JEXL-193:


I've been able to fix it locally by patching Interpreter.java 

{code}
public Object interpret(JexlNode node) {

} catch (JexlException xjexl) {
if (xjexl instanceof JexlException.Cancel) {
throw xjexl;
} else if (silent) {
logger.warn(xjexl.getMessage(), xjexl.getCause());
return null;
}
throw xjexl.clean();
...
{code}

and adding additional catch 

{code}
protected Object call(final JexlNode node, Object target, Object functor, 
final ASTArguments argNode) {
...
} catch (InvocationTargetException ite) {

Throwable targetException = ite.getTargetException();

if (targetException instanceof InterruptedException) {
   throw new JexlException.Cancel(node);
}

xjexl = new JexlException(node, methodName, ite);
  
{code}

Hope this'll help to fix it...

> InterruptedException is swallowed in function call in silent and non-strict 
> mode
> 
>
> Key: JEXL-193
> URL: https://issues.apache.org/jira/browse/JEXL-193
> Project: Commons JEXL
>  Issue Type: Bug
>Affects Versions: 3.0
>Reporter: Dmitri Blinov
>
> The following test case fails with 
> {code}
> java.lang.AssertionError: Values should be different. Actual: 42
>   at org.junit.Assert.fail(Assert.java:88)
>   at org.junit.Assert.failEquals(Assert.java:185)
>   at org.junit.Assert.assertNotEquals(Assert.java:161)
> {code}
> {code}
> public static class TestContext extends MapContext implements 
> JexlContext.NamespaceResolver {
> public int interrupt() throws InterruptedException {
> throw new InterruptedException();
> }
> }
> @Test
> public void testInterrupt() throws Exception {
> JexlEngine jexl = new JexlBuilder().arithmetic(new 
> JexlArithmetic(false)).strict(false).silent(true).create();
> JexlScript e = jexl.createScript("interrupt(); return 42");
> Callable c = e.callable(new TestContext());
> Object t = c.call();
> Assert.assertNotEquals(42, t);
> }
> {code}
> Expected behaviour is to cancel script execution



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