Uploaded image for project: 'Commons JEXL'
  1. Commons JEXL
  2. JEXL-204

Script is not interrupted by a method call throwing Exception

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Invalid
    • Affects Version/s: 3.0
    • Fix Version/s: 3.1
    • Labels:
      None

      Description

      The following test case fails with the message

      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)

      @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);
          }
      }
      

        Attachments

          Activity

            People

            • Assignee:
              henrib Henri Biestro
              Reporter:
              dmitri_blinov Dmitri Blinov
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: