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

Executable model doesn't provide error when using Variable inside bindings

    XMLWordPrintable

Details

    • Enhancement
    • Resolution: Done
    • Major
    • None
    • 7.58.0.Final
    • executable model
    • None

    Description

      It's not possible to use variables inside bindings. Here's the reproducer

      Executable model should report the error

          @Test
          public void testVariableInsideBinding() {
              String str =
                      "import " + Person.class.getCanonicalName() + ";" +
                              "import " + NameLengthCount.class.getCanonicalName() + ";" +
                              "rule X when\n" +
                              "  $nlc : NameLengthCount() \n" +
                              "  Person ( $nameLength : $nlc.getNameLength(name))" +
                              "then\n" +
                              "end";
      
              Results results = createKieBuilder(str ).getResults();
              assertThat(results.getMessages(Message.Level.ERROR).stream().map(Message::getText))
                      .contains("Variables can not be used inside bindings. Variable [$nlc] is being used in binding '$nlc.getNameLength(name)'");
          }
      
          public static class NameLengthCount {
              public int getNameLength(String name) {
                  return name.length();
              }
          }
      

      Attachments

        Issue Links

          Activity

            People

              lmolteni@redhat.com Luca Molteni
              lmolteni@redhat.com Luca Molteni
              Daniel Rosa Daniel Rosa
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: