Uploaded image for project: 'Drools'
  1. Drools
  2. DROOLS-889

Ambiguity with 'end' keyword and end() method in drl file

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 6.3.0.CR2
    • None
    • None
    • None
    • NEW
    • NEW

      Trying to invoke a method called end() in the RHS of a rule, as in the test case pasted below, causes a compilation failure because drools interprets it as the 'end' soft keyword that terminates the rule.

          @Test
          public void testEndMethod() throws Exception {
              // DROOLS-889
              String drl =
                      "import " + Pattern.class.getCanonicalName() + "\n" +
                      "import " + Matcher.class.getCanonicalName() + "\n" +
                      "global java.util.List list\n" +
                      "rule \"Variable matches field\" when\n" +
                      "    $emailAddress :String(this matches \"^.*[_A-Za-z0-9-\\\\+]+(\\\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\\\.[A-Za-z0-9]+)*(\\\\.[A-Za-z]{2,}).*$\")\n" +
                      "then\n" +
                      "    Pattern pattern=Pattern.compile(\"[_A-Za-z0-9-\\\\+]+(\\\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\\\.[A-Za-z0-9]+)*(\\\\.[A-Za-z]{2,})\");\n" +
                      "    Matcher matcher=pattern.matcher($emailAddress);\n" +
                      "    while(matcher.find()){\n" +
                      "        list.add($emailAddress.substring(matcher.start(),matcher.end()));\n" +
                      "    }\n" +
                      "end\n";
      
              KieSession ksession = new KieHelper().addContent(drl, ResourceType.DRL)
                                                   .build()
                                                   .newKieSession();
      
              List<String> list = new ArrayList<String>();
              ksession.setGlobal( "list", list );
      
              ksession.insert( "mario.fusco@test.org" );
              ksession.fireAllRules();
      
              assertEquals( 1, list.size() );
              assertEquals( "mario.fusco@test.org", list.get(0) );
          }
      

            mfusco@redhat.com Mario Fusco
            mfusco@redhat.com Mario Fusco
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: