This is an automated email from the ASF dual-hosted git repository. henrib pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-jexl.git
The following commit(s) were added to refs/heads/master by this push: new 2aa57b9 JEXL-256: a test/sample for throwing (jexl) exception from a context set 2aa57b9 is described below commit 2aa57b95b48811b0df1aabe4d613f9ee4806ea1c Author: Henri Biestro <hen...@apache.org> AuthorDate: Wed Apr 11 22:51:25 2018 +0200 JEXL-256: a test/sample for throwing (jexl) exception from a context set --- .../org/apache/commons/jexl3/Issues200Test.java | 54 ++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/src/test/java/org/apache/commons/jexl3/Issues200Test.java b/src/test/java/org/apache/commons/jexl3/Issues200Test.java index a19d6cf..e8df901 100644 --- a/src/test/java/org/apache/commons/jexl3/Issues200Test.java +++ b/src/test/java/org/apache/commons/jexl3/Issues200Test.java @@ -387,6 +387,22 @@ public class Issues200Test extends JexlTestCase { } catch (JexlException xany) { Assert.fail("Should have evaluated to null"); } + try { + stmt = "x?.y?.z"; + script = engine.createScript(stmt); + result = script.execute(ctx); + Assert.assertNull(result); + } catch (JexlException xany) { + Assert.fail("Should have evaluated to null"); + } + try { + stmt = "x? (x.y? (x.y.z ?: null) :null) : null"; + script = engine.createScript(stmt); + result = script.execute(ctx); + Assert.assertNull(result); + } catch (JexlException xany) { + Assert.fail("Should have evaluated to null"); + } } @Test @@ -410,4 +426,42 @@ public class Issues200Test extends JexlTestCase { String xanystr = xany.toString(); } } + + @Test + public void test256() throws Exception { + MapContext ctx = new MapContext() { + @Override public void set(String name, Object value) { + if ("java".equals(name)) { + throw new JexlException(null, "can not set " + name); + } + super.set(name, value); + } + @Override public Object get(String name) { + if ("java".equals(name)) { + return null; + } + return super.get(name); + } + @Override public boolean has(String name) { + if ("java".equals(name)) { + return false; + } + return super.has(name); + } + }; + ctx.set("java.version", 10); + JexlEngine engine = new JexlBuilder().strict(true).silent(false).create(); + Object result = null; + JexlScript script; + script = engine.createScript("java = 3"); + try { + script.execute(ctx); + Assert.fail("should have failed!"); + } catch(JexlException xjexl) { + // expected + } + script = engine.createScript("java.version"); + result = script.execute(ctx); + Assert.assertEquals(10, result); + } } -- To stop receiving notification emails like this one, please contact hen...@apache.org.