[jira] [Commented] (JEXL-306) Ternary operator ? protects also its branches from resolution errors
[ https://issues.apache.org/jira/browse/JEXL-306?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16860139#comment-16860139 ] Henri Biestro commented on JEXL-306: Intermediate commit https://github.com/apache/commons-jexl/commit/a69782bea469a766f71f12f76e9d5154b7415be4 > Ternary operator ? protects also its branches from resolution errors > > > Key: JEXL-306 > URL: https://issues.apache.org/jira/browse/JEXL-306 > Project: Commons JEXL > Issue Type: Bug >Affects Versions: 3.1 >Reporter: Dmitri Blinov >Assignee: Henri Biestro >Priority: Major > Fix For: 3.2 > > > Consider the following test case (suppose its added to IfTest) > {code:java} > @Test > public void testTernaryFail() throws Exception { > JexlEvalContext jc = new JexlEvalContext(); > JexlExpression e = JEXL.createExpression("false ? bar : quux"); > Object o; > jc.setStrict(true); > jc.setSilent(false); > try { > o = e.evaluate(jc); > Assert.fail("Should have failed"); > } catch (Exception ex) { > // OK > } > } > {code} > The expected behavior is to fail with {{undefined variable...}} because > neither {{bar}} nor {{quux}} is defined -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (JEXL-306) Ternary operator ? protects also its branches from resolution errors
[ https://issues.apache.org/jira/browse/JEXL-306?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16860093#comment-16860093 ] Dmitri Blinov commented on JEXL-306: Regarding the first part of the question. Lets start with {{x?.y}}. My understanding is that this operator is simply an inline for {code}if (x == null) return null else return x.y{code} The {{else}} part of the {{if}} is an ordinary unprotected property access operator that should behave just as simple {{x.y}}. So we can keep {{?.} aside and focus on {{??}}, {{?:}}. I''l try to summarize what we have now for ternaries. The operator {{\??}} is the most simple case because its only checks its left side for {{null}} or undefined. The elvis operator {{?:}} is like {{??}} but checks its left side not only for {{null}} or undefined, but also for the left side to be logically {{false}}. Conventional ternary operator {{? : }} is like {{?:}} elvis operator regarding its left-side operand, but allows to specify a value not only for {{false}} but also for {{true}}. So, I think all ternaries differ only in their result part, and should be equal in their treatment of the left part > Ternary operator ? protects also its branches from resolution errors > > > Key: JEXL-306 > URL: https://issues.apache.org/jira/browse/JEXL-306 > Project: Commons JEXL > Issue Type: Bug >Affects Versions: 3.1 >Reporter: Dmitri Blinov >Assignee: Henri Biestro >Priority: Major > Fix For: 3.2 > > > Consider the following test case (suppose its added to IfTest) > {code:java} > @Test > public void testTernaryFail() throws Exception { > JexlEvalContext jc = new JexlEvalContext(); > JexlExpression e = JEXL.createExpression("false ? bar : quux"); > Object o; > jc.setStrict(true); > jc.setSilent(false); > try { > o = e.evaluate(jc); > Assert.fail("Should have failed"); > } catch (Exception ex) { > // OK > } > } > {code} > The expected behavior is to fail with {{undefined variable...}} because > neither {{bar}} nor {{quux}} is defined -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (JEXL-306) Ternary operator ? protects also its branches from resolution errors
[ https://issues.apache.org/jira/browse/JEXL-306?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16860053#comment-16860053 ] Dmitri Blinov commented on JEXL-306: Regarding second part of the question, consider the following example {code}x.y ? 1 : 2{code} It returns 2 because x.y is undefined ant-ish variable. Another example that returns 2 is {code}var x = {'a':1}; x.y ? 1 : 2{code} My opinion is that we would expect predicted equal behaviour from syntactically equal constructs. So yes - ternaries should protect from unsolvable properties. > Ternary operator ? protects also its branches from resolution errors > > > Key: JEXL-306 > URL: https://issues.apache.org/jira/browse/JEXL-306 > Project: Commons JEXL > Issue Type: Bug >Affects Versions: 3.1 >Reporter: Dmitri Blinov >Assignee: Henri Biestro >Priority: Major > Fix For: 3.2 > > > Consider the following test case (suppose its added to IfTest) > {code:java} > @Test > public void testTernaryFail() throws Exception { > JexlEvalContext jc = new JexlEvalContext(); > JexlExpression e = JEXL.createExpression("false ? bar : quux"); > Object o; > jc.setStrict(true); > jc.setSilent(false); > try { > o = e.evaluate(jc); > Assert.fail("Should have failed"); > } catch (Exception ex) { > // OK > } > } > {code} > The expected behavior is to fail with {{undefined variable...}} because > neither {{bar}} nor {{quux}} is defined -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (JEXL-306) Ternary operator ? protects also its branches from resolution errors
[ https://issues.apache.org/jira/browse/JEXL-306?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16859823#comment-16859823 ] Henri Biestro commented on JEXL-306: Regression, reopen. Sorry > Ternary operator ? protects also its branches from resolution errors > > > Key: JEXL-306 > URL: https://issues.apache.org/jira/browse/JEXL-306 > Project: Commons JEXL > Issue Type: Bug >Affects Versions: 3.1 >Reporter: Dmitri Blinov >Assignee: Henri Biestro >Priority: Major > Fix For: 3.2 > > > Consider the following test case (suppose its added to IfTest) > {code:java} > @Test > public void testTernaryFail() throws Exception { > JexlEvalContext jc = new JexlEvalContext(); > JexlExpression e = JEXL.createExpression("false ? bar : quux"); > Object o; > jc.setStrict(true); > jc.setSilent(false); > try { > o = e.evaluate(jc); > Assert.fail("Should have failed"); > } catch (Exception ex) { > // OK > } > } > {code} > The expected behavior is to fail with {{undefined variable...}} because > neither {{bar}} nor {{quux}} is defined -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (JEXL-306) Ternary operator ? protects also its branches from resolution errors
[ https://issues.apache.org/jira/browse/JEXL-306?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16859816#comment-16859816 ] Dmitri Blinov commented on JEXL-306: The following script throws an exception "Undefined property y" {code:java} var x = new ("java.lang.Object"); x.y ? 1 : 2{code} I'm confused, is it a supposed behaviour? Should it return {{2}} just like in {code:java} x ? 1 : 2{code} > Ternary operator ? protects also its branches from resolution errors > > > Key: JEXL-306 > URL: https://issues.apache.org/jira/browse/JEXL-306 > Project: Commons JEXL > Issue Type: Bug >Affects Versions: 3.1 >Reporter: Dmitri Blinov >Assignee: Henri Biestro >Priority: Major > Fix For: 3.2 > > > Consider the following test case (suppose its added to IfTest) > {code:java} > @Test > public void testTernaryFail() throws Exception { > JexlEvalContext jc = new JexlEvalContext(); > JexlExpression e = JEXL.createExpression("false ? bar : quux"); > Object o; > jc.setStrict(true); > jc.setSilent(false); > try { > o = e.evaluate(jc); > Assert.fail("Should have failed"); > } catch (Exception ex) { > // OK > } > } > {code} > The expected behavior is to fail with {{undefined variable...}} because > neither {{bar}} nor {{quux}} is defined -- This message was sent by Atlassian JIRA (v7.6.3#76005)