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

Ternary Conditional fails for Object values

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.1, 2.1.1
    • 2.1.2, 3.0
    • None

    Description

      The documentation states on http://commons.apache.org/jexl/reference/syntax.html#Operators :

      The usual ternary conditional operator condition ? if_true : if_false operator can be used as well as the
      abbreviation value ?: if_false which returns the value if its evaluation is defined, non-null and non-false

      For object values however, it seems that this definition no longer holds in 2.1 and higher.

      The following unittests run successfully in 2.0.1, but the test "ternaryConditional_mapContainsObject_shouldReturnObject" fails in 2.1 and 2.1.1.

      import org.apache.commons.jexl2.*;
      import org.junit.*;
      
      public class JexlTernaryConditionalTest
      {
          @Test
          public void ternaryConditional_mapContainsString_shouldReturnString()
          {
              String myName = "Test.Name";
              Object myValue = "Test.Value";
      
              JexlEngine myJexlEngine = new JexlEngine();
              MapContext myMapContext = new MapContext();
              myMapContext.set(myName, myValue);
      
              Object myObjectWithTernaryConditional = myJexlEngine.createScript(myName + "?:null").execute(myMapContext);
              Assert.assertEquals(myValue, myObjectWithTernaryConditional);
          }
      
          @Test
          public void ternaryConditional_mapContainsObject_shouldReturnObject()
          {
              String myName = "Test.Name";
              Object myValue = new Object();
      
              JexlEngine myJexlEngine = new JexlEngine();
              MapContext myMapContext = new MapContext();
              myMapContext.set(myName, myValue);
      
              Object myObjectWithTernaryConditional = myJexlEngine.createScript(myName + "?:null").execute(myMapContext);
              Assert.assertEquals(myValue, myObjectWithTernaryConditional);
          }
      }
      

      Attachments

        Activity

          People

            henrib Henri Biestro
            wbakker William Bakker
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: