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

Incorrect invoking methods with ObjectContext

    XMLWordPrintableJSON

Details

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

    Description

      After apply fix in JEXL-190 folowing code doesn't work anymore:

      public class Example {
          public static void main(String[] args) {
              JexlEngine jexl = new JexlBuilder().create();
      
              ObjectContext<Foo> context = new ObjectContext<>(jexl, new Foo());
              JexlExpression expression = jexl.createExpression("bar()");
      
              System.out.println(expression.evaluate(context));
          }
      
          public static class Foo extends HashMap<String, Object>{
              public String bar(){
                  return "bar";
              }
          }
      }
      

      Also doesn't work this code:

      public class Example {
          public static void main(String[] args) {
              HashMap<String, Object> functions = new HashMap<>();
              functions.put(null, new DefaultFunctions());
      
              JexlEngine jexl = new JexlBuilder()
                      .namespaces(functions)
                      .create();
      
              ObjectContext<Object> context = new ObjectContext<>(jexl, new Object());
              JexlExpression expression = jexl.createExpression("bar()");
      
              System.out.println(expression.evaluate(context));
          }
      
          public static class DefaultFunctions {
              public String bar(){
                  return "bar";
              }
          }
      }
      

      Output:

      Example.main@1:4 unsolvable function/method 'bar'
      

      note: with MapContext all working correct

      Attachments

        Activity

          People

            henrib Henri Biestro
            dpatriot Vyacheslav Shago
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: