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

Array access operator does not fail on null object in non-strict arithmetic mode

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.1
    • 3.2
    • None

    Description

      Consider the following test cases

          @Test
          public void testNullArrayAccess() throws Exception {
              JexlEngine jexl = new JexlBuilder().arithmetic(new JexlArithmetic(false)).create();
              JexlScript s = jexl.createScript("var x = null; x[0]");
              try {
                 Object o = s.execute(null);
                 Assert.fail("Should have failed");
              } catch (Exception ex) {
                 //
              }
          }
      

      and

          @Test
          public void testNullArrayAccess2() throws Exception {
              JexlEngine jexl = new JexlBuilder().arithmetic(new JexlArithmetic(false)).create();
              JexlScript s = jexl.createScript("var x = [null,1]; x[0][0]");
              try {
                 Object o = s.execute(null);
                 Assert.fail("Should have failed");
              } catch (Exception ex) {
                 //
              }
          }
      

      I exect array access operator to work identically in both cases, i.e. we should fail on trying to get an array element of null. Nevertheless, only the second case fails. I think this is a bug.

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: