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

Variable length argument lists lose arguments in MVEL

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Major
    • 6.3.0.Beta1
    • 6.1.0.Final
    • core engine
    • None
    • Hide

      Define a class

      public class Assertion {
         public String keyword;
         public final List<String> parameters = new ArrayList<>();
         
         public Assertion(String keyword, String... params) {
      	this.keyword = keyword;
      	for (String param: params) {
      		parameters.add(param);
      	}
         }
      
      @Override
        public String toString() {
      	String result = keyword;
      	for (String param: parameters) {
      		result += " " + param;
      	}
      	return result;
      }
      

      Now define rules

      rule "Unexpected input type when slide navigation is expected"
      dialect "mvel"
          when
              not(Assertion())
          then
          	insert(new Assertion("UNEXPECTED_CONTENT", "KW1", "KW2"))
      end
      
      
      rule "Unexpected input type when slide navigation is expected"
      dialect "mvel"
          when
              $assert: Assertion()
          then
               System.out.println($assert);
               retract($assert);
      end
      

      Expected output:
      "UNEXPECTED_CONTENT KW1 KW2"
      Actual output:
      "UNEXPECTED_CONTENT KW1"

      I have walked it through with a debugger, and KW2 is never passed to the constructor.

      Show
      Define a class public class Assertion { public String keyword; public final List< String > parameters = new ArrayList<>(); public Assertion( String keyword, String ... params) { this .keyword = keyword; for ( String param: params) { parameters.add(param); } } @Override public String toString() { String result = keyword; for ( String param: parameters) { result += " " + param; } return result; } Now define rules rule "Unexpected input type when slide navigation is expected" dialect "mvel" when not(Assertion()) then insert( new Assertion( "UNEXPECTED_CONTENT" , "KW1" , "KW2" )) end rule "Unexpected input type when slide navigation is expected" dialect "mvel" when $ assert : Assertion() then System .out.println($ assert ); retract($ assert ); end Expected output: "UNEXPECTED_CONTENT KW1 KW2" Actual output: "UNEXPECTED_CONTENT KW1" I have walked it through with a debugger, and KW2 is never passed to the constructor.

    Description

      When I use a method with variable number of arguments (e.g., String... args) in MVEL, the first one is passed on, and the others are discarded, leading to confusing and difficult to debug bugs. It should either support this, or report a compilation error.

      Attachments

        Activity

          People

            mfusco@redhat.com Mario Fusco
            myrosia_jira Myroslava Dzikovska (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: