-
Task
-
Resolution: Unresolved
-
Major
-
None
-
7.47.0.Final
-
None
-
Undefined
-
NEW
-
NEW
-
---
-
---
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