[
https://issues.redhat.com/browse/DROOLS-5921?page=com.atlassian.jira.plug...
]
Toshiya Kobayashi updated DROOLS-5921:
--------------------------------------
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.
{code:java}
@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);
}
{code}
{noformat}
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 )
{noformat}
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/...
https://github.com/kiegroup/drools/blob/master/drools-core/src/main/java/...
Also we need to consider backward compatibility.
Note: You can work around this issue by explicitly setting default values.
{noformat}
declare MyFact
strValue: java.lang.String = null
intValue: java.lang.Integer = null
booleanValue: java.lang.Boolean = null
end
{noformat}
was:
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.
{code:java}
@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);
}
{code}
{noformat}
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 )
{noformat}
standard-drl seems to intentionally set the values to meet primitives' default values
but probably "null" is the better default value.
https://github.com/kiegroup/drools/blob/master/drools-core/src/main/java/...
https://github.com/kiegroup/drools/blob/master/drools-core/src/main/java/...
Also we need to consider backward compatibility.
Note: You can work around this issue by explicitly setting default values.
{noformat}
declare MyFact
strValue: java.lang.String = null
intValue: java.lang.Integer = null
booleanValue: java.lang.Boolean = null
end
{noformat}
Declared type fields implicit default values
--------------------------------------------
Key: DROOLS-5921
URL:
https://issues.redhat.com/browse/DROOLS-5921
Project: Drools
Issue Type: Task
Components: core engine, executable model
Affects Versions: 7.47.0.Final
Reporter: Toshiya Kobayashi
Assignee: Toshiya Kobayashi
Priority: Major
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.
{code:java}
@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);
}
{code}
{noformat}
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 )
{noformat}
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/...
https://github.com/kiegroup/drools/blob/master/drools-core/src/main/java/...
Also we need to consider backward compatibility.
Note: You can work around this issue by explicitly setting default values.
{noformat}
declare MyFact
strValue: java.lang.String = null
intValue: java.lang.Integer = null
booleanValue: java.lang.Boolean = null
end
{noformat}
--
This message was sent by Atlassian Jira
(v7.13.8#713008)