MVEL
  1. MVEL
  2. MVEL-60

nullpointer when using foreach on a root object's collection

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.2.10
    • Fix Version/s: 1.2.11
    • Component/s: Templating
    • Labels:
      None
    • Testcase included:
      yes
    • Number of attachments :
      1

      Description

      In the attached test case test0, test2 and test3 work as expected, but test1 throws a nullpointer exception. This occurs when a template iterates over a collection of the root object, or a collection of a property of a root object. The tests show that the error does not occur when the collection is a property of an entry in the map

      Eg

      test0 - works
      String template = "@foreach

      {list}

      a@end{}";
      Map map = new HashMap();
      map.put("list",list);
      String r = TemplateInterpreter.evalToString(template,map);

      test1 - fails
      Folder f1 = new Folder("f1",null);
      String template = "@

      {name}

      @foreach

      {children}

      a@end{}";
      String r = TemplateInterpreter.evalToString(template,f1);

      class Folder extends Page

      { public List<Page> getChildren() }

        Activity

        Hide
        brad mcevoy added a comment -

        Here's an example stack trace

        org.mvel.CompileException: problem encountered at node [2] 1

        {8,26}

        : null
        at org.mvel.TemplateInterpreter.execute(TemplateInterpreter.java:528)
        at org.mvel.TemplateInterpreter.execute(TemplateInterpreter.java:345)
        at org.mvel.TemplateInterpreter.eval(TemplateInterpreter.java:98)
        at org.mvel.TemplateInterpreter.evalToString(TemplateInterpreter.java:61)
        at com.bradmcevoy.web.TestMvel.test1(TestMvel.java:38)
        Caused by: java.lang.NullPointerException
        at org.mvel.TemplateInterpreter.execute(TemplateInterpreter.java:463)

        Show
        brad mcevoy added a comment - Here's an example stack trace org.mvel.CompileException: problem encountered at node [2] 1 {8,26} : null at org.mvel.TemplateInterpreter.execute(TemplateInterpreter.java:528) at org.mvel.TemplateInterpreter.execute(TemplateInterpreter.java:345) at org.mvel.TemplateInterpreter.eval(TemplateInterpreter.java:98) at org.mvel.TemplateInterpreter.evalToString(TemplateInterpreter.java:61) at com.bradmcevoy.web.TestMvel.test1(TestMvel.java:38) Caused by: java.lang.NullPointerException at org.mvel.TemplateInterpreter.execute(TemplateInterpreter.java:463)
        Mike Brock made changes -
        Field Original Value New Value
        Status Open [ 1 ] In Progress [ 3 ]
        Mike Brock made changes -
        Resolution Fixed [ 1 ]
        Status In Progress [ 3 ] Closed [ 6 ]
        Fix Version/s 1.2.11 [ 13807 ]

          People

          • Assignee:
            Mike Brock
            Reporter:
            brad mcevoy
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: