MVEL
  1. MVEL
  2. MVEL-218

Bracket not working properly

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Blocker Blocker
    • Resolution: Not A Bug
    • Affects Version/s: 2.0.17
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Environment:
      Mac OSX 10.6
      JDK 1.6
    • Testcase included:
      yes
    • Number of attachments :
      0

      Description

      The bracket is not working properly in the logical expression like '(1 == 1) and (2 > 1)'. It is working fine without bracket.

      Here is the test case:
      public void testCalculate4() {
      Map vars = new LinkedHashMap();

      String[] testCases =

      { "(1 == 1) and (2 > 1)",// "(1 == 1) and (2 > 1) and (3!=4) and (4!=3)",// "( 2 + 3 > 4 ) and ( 8 - 5 > 2 )",// "(2+3>4) and (8-5>2)",// "1 == 1 and 2 > 1 and (3!=4 and 4!=3)" // }

      ;

      for (String expr : testCases)

      { log.info("Evaluating '" + expr + "': ......"); Object ret = MVEL.eval(expr, vars); log.info("'" + expr + " ' = " + ret.toString()); Assert.assertNotNull(ret); // test in compile mode Serializable compiled = MVEL.compileExpression(expr); ret = MVEL.executeExpression(compiled, vars); log.info("'" + expr + " ' = " + ret.toString()); Assert.assertNotNull(ret); }

      }

        Activity

        Hide
        Mike Brock added a comment -

        This problem is being caused by your use of "and" instead of "&&" for your boolean operator. While "and" is a reserved operator, it is ignored by the parser. In hindsight it shouldn't. Future versions of MVEL will throw an exception if you try to use "and" instead of "&&"

        Show
        Mike Brock added a comment - This problem is being caused by your use of "and" instead of "&&" for your boolean operator. While "and" is a reserved operator, it is ignored by the parser. In hindsight it shouldn't. Future versions of MVEL will throw an exception if you try to use "and" instead of "&&"

          People

          • Assignee:
            Mike Brock
            Reporter:
            Rojer Luo Jun
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: