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

Declared type fields implicit default values

    XMLWordPrintable

Details

    • Task
    • Resolution: Unresolved
    • Major
    • None
    • 7.47.0.Final
    • None
    • Undefined
    • NEW
    • NEW
    • ---
    • ---

    Description

      When we define a declared type and omit field default values, default values will be given implicitly. The values differ between standard-drl and executable-model.

          @Test
          public void testDefaultValues() throws Exception {
              String str =
                      "package org.test;\n" +
                           "declare MyFact\n" +
                           "    stringValue : String\n" +
                           "    intValue : Integer\n" +
                           "    booleanValue :  Boolean\n" +
                           "end\n" +
                           "rule R when\n" +
                           "  MyFact( )\n" +
                           "then\n" +
                           "end";
      
              KieSession ksession = getKieSession(str);
      
              FactType factType = ksession.getKieBase().getFactType("org.test", "MyFact");
              Object factInstance = factType.newInstance();
              System.out.println(factInstance);
          }
      
      STANDARD_FROM_DRL : MyFact( stringValue=null, intValue=0, booleanValue=false )
      FLOW_DSL : MyFact( stringValue=null, intValue=null, booleanValue=null )
      PATTERN_DSL : MyFact( stringValue=null, intValue=null, booleanValue=null )
      

      standard-drl seems to intentionally set the values to meet primitives' default values but probably "null" is the better default.

      https://github.com/kiegroup/drools/blob/master/drools-core/src/main/java/org/drools/core/factmodel/FieldDefinition.java#L380
      https://github.com/kiegroup/drools/blob/master/drools-core/src/main/java/org/drools/core/factmodel/FieldDefinition.java#L335

      Also we need to consider backward compatibility.

      Note: You can work around this issue by explicitly setting default values.

      declare MyFact
        strValue: java.lang.String = null
        intValue: java.lang.Integer = null
        booleanValue: java.lang.Boolean = null
      end
      

      Attachments

        Activity

          People

            rhn-support-tkobayas Toshiya Kobayashi
            rhn-support-tkobayas Toshiya Kobayashi
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: