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

serialVersionUID included in all-arguments constructor

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Minor Minor
    • None
    • 7.37.0.Final
    • None
    • None
    • 2020 Week 19-21 (from May 4)
    • Hide

      Create any DRL and in RHS try to call the constructor for the fact using all arguments.

      E.g.

      declare InputInformation
          firstName: String
          lastName: String
      end
      
      declare ServiceInformation
          @serialVersionUID( 0 )
          code: String @key
          text : String
          associations : List
      end
      
      rule "Match first and last name"
      when 
          InputInformation(firstName == "John", lastName == "Doe")
      then 
         insert( new ServiceInformation("123456", "ServiceTest", new ArrayList()) );
      end
      

      Running it produces:

      constructor ServiceInformation() is not applicable
      [ERROR]       (actual and formal argument lists differ in length)
      [ERROR]     constructor ServiceInformation(java.lang.String,java.lang.String,java.util.List,long) is not applicable
      [ERROR]       (actual and formal argument lists differ in length)
      [ERROR]     constructor ServiceInformation(java.lang.String) is not applicable
      

      The serialVersionUID is a static (not final) field which is added to the constructor.

      Show
      Create any DRL and in RHS try to call the constructor for the fact using all arguments. E.g. declare InputInformation firstName: String lastName: String end declare ServiceInformation @serialVersionUID( 0 ) code: String @key text : String associations : List end rule "Match first and last name" when InputInformation(firstName == "John" , lastName == "Doe" ) then insert( new ServiceInformation( "123456" , "ServiceTest" , new ArrayList()) ); end Running it produces: constructor ServiceInformation() is not applicable [ERROR] (actual and formal argument lists differ in length) [ERROR] constructor ServiceInformation(java.lang. String ,java.lang. String ,java.util.List, long ) is not applicable [ERROR] (actual and formal argument lists differ in length) [ERROR] constructor ServiceInformation(java.lang. String ) is not applicable The serialVersionUID is a static (not final) field which is added to the constructor.
    • Documentation (Ref Guide, User Guide, etc.)
    • Workaround Exists
    • Hide

      Create the Drools fact using no-args constructor and populate it using accessors.

      Show
      Create the Drools fact using no-args constructor and populate it using accessors.
    • NEW
    • NEW

      In the consequence (RHS) of the rule, when trying to insert a fact using a constructor with all declared (non-static) fields, Drools reports an error stating that no viable constructor was found.

              mfusco@redhat.com Mario Fusco
              pexcom Alin Rauta (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: