Error creating shadow fact for object: [] when inserting Collection into working memory
by Henry Canterburry
I am having the same problem as described in this post:
http://www.nabble.com/The-effect-of-not-using-shadow-facts-tp11652637p117...
The problem is, there really was no solution mentioned. Here is my
collections class that I am asserting into working memory:
public class NamedCollection<T> extends LinkedList<T>{
public NamedCollection(String name){
super();
this.name = name;
}
public String getName(){
return name;
}
/**
*
*/
private static final long serialVersionUID = -457439174592908333L;
private String name;
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
final NamedCollection other = (NamedCollection) obj;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
return true;
}
}
I get the following error when inserting this fact into memory:
org.drools.RuntimeDroolsException: Error creating shadow fact for object: []
at org.drools.reteoo.Rete$ClassObjectTypeConf.getShadow(Rete.java:628)
at org.drools.reteoo.Rete.assertObject(Rete.java:166)
at
org.drools.reteoo.ReteooRuleBase.assertObject(ReteooRuleBase.java:192)
at
org.drools.reteoo.ReteooWorkingMemory.doInsert(ReteooWorkingMemory.java:71)
at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:886)
at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:858)
at
org.drools.base.DefaultKnowledgeHelper.insert(DefaultKnowledgeHelper.java:60)
at
org.drools.base.DefaultKnowledgeHelper.insert(DefaultKnowledgeHelper.java:54)
at
sequitem.quanteq.ruleflow.Rule_Explode_Globals_0.consequence(Rule_Explode_Globals_0.java:15)
at
sequitem.quanteq.ruleflow.Rule_Explode_Globals_0ConsequenceInvoker.evaluate(Rule_Explode_Globals_0ConsequenceInvoker.java:22)
at
org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:550)
at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:514)
at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:462)
at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:424)
at
sequitem.quanteq.rules.engine.StatefulEngine.execute(StatefulEngine.java:50)
at
sequitem.quanteq.rules.engine.StatefulEngine.execute(StatefulEngine.java:24)
at
sequitem.quanteq.rules.RandomMarketEntryRulesTest.testRandomMarketEntryRules(RandomMarketEntryRulesTest.java:56)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at junit.framework.TestCase.runTest(TestCase.java:168)
at junit.framework.TestCase.runBare(TestCase.java:134)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at junit.textui.TestRunner.doRun(TestRunner.java:116)
at junit.textui.TestRunner.doRun(TestRunner.java:109)
at junit.textui.TestRunner.run(TestRunner.java:77)
at junit.textui.TestRunner.run(TestRunner.java:62)
at
sequitem.quanteq.rules.RandomMarketEntryRulesTest.main(RandomMarketEntryRulesTest.java:64)
Caused by: java.lang.NullPointerException
at java.util.LinkedList.clear(LinkedList.java:292)E
at
sequitem.quanteq.rules.engine.NamedCollectionShadowProxy.updateProxy(Unknown
Source)
at
sequitem.quanteq.rules.engine.NamedCollectionShadowProxy.setShadowedObject(Unknown
Source)
at org.drools.reteoo.Rete$ClassObjectTypeConf.getShadow(Rete.java:626)
... 33 more
Time: 67.75
There was 1 error:
1)
testRandomMarketEntryRules(sequitem.quanteq.rules.RandomMarketEntryRulesTest)org.drools.spi.ConsequenceException:
org.drools.RuntimeDroolsException: Error creating shadow fact for object: []
at
org.drools.base.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:14)
at
org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:553)
at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:514)
at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:462)
at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:424)
at
sequitem.quanteq.rules.engine.StatefulEngine.execute(StatefulEngine.java:50)
at
sequitem.quanteq.rules.engine.StatefulEngine.execute(StatefulEngine.java:24)
at
sequitem.quanteq.rules.RandomMarketEntryRulesTest.testRandomMarketEntryRules(RandomMarketEntryRulesTest.java:56)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at
sequitem.quanteq.rules.RandomMarketEntryRulesTest.main(RandomMarketEntryRulesTest.java:64)
Caused by: org.drools.RuntimeDroolsException: Error creating shadow fact
for object: []
at org.drools.reteoo.Rete$ClassObjectTypeConf.getShadow(Rete.java:628)
at org.drools.reteoo.Rete.assertObject(Rete.java:166)
at
org.drools.reteoo.ReteooRuleBase.assertObject(ReteooRuleBase.java:192)
at
org.drools.reteoo.ReteooWorkingMemory.doInsert(ReteooWorkingMemory.java:71)
at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:886)
at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:858)
at
org.drools.base.DefaultKnowledgeHelper.insert(DefaultKnowledgeHelper.java:60)
at
org.drools.base.DefaultKnowledgeHelper.insert(DefaultKnowledgeHelper.java:54)
at
sequitem.quanteq.ruleflow.Rule_Explode_Globals_0.consequence(Rule_Explode_Globals_0.java:15)
at
sequitem.quanteq.ruleflow.Rule_Explode_Globals_0ConsequenceInvoker.evaluate(Rule_Explode_Globals_0ConsequenceInvoker.java:22)
at
org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:550)
... 23 more
Caused by: java.lang.NullPointerException
at java.util.LinkedList.clear(LinkedList.java:292)
at
sequitem.quanteq.rules.engine.NamedCollectionShadowProxy.updateProxy(Unknown
Source)
at
sequitem.quanteq.rules.engine.NamedCollectionShadowProxy.setShadowedObject(Unknown
Source)
at org.drools.reteoo.Rete$ClassObjectTypeConf.getShadow(Rete.java:626)
... 33 more
16 years, 11 months
Strange property access behavior resulting in NullPointerException
by Henry Canterburry
I am using Drools 4.0.3. I have a rule that I believe should work but
causes a NullPointerException at runtime.
The rule phrased this way causes a NullPointerException:
rule "Create Order Limit"
when
CandleSeries( $instrument : instrumentSpecification )
then
insert(new OrderConstraint( $instrument ));
end
While the same rule phased like this works fine:
rule "Create Order Limit"
when
$candle : CandleSeries( )
then
insert(new OrderConstraint( $candle.getInstrumentSpecification()
));
end
Is this right? I was looking at rule example 10.27 in the Drools guide
and it's written exactly like rule #1 is.
Here is the full stack trace of the rule execution from version 1:
java.lang.NullPointerException
at
org.activequant.core.domainmodel.TimeSeries.getInstrumentSpecification(Unknown
Source)
at
org.drools.base.org.activequant.core.domainmodel.CandleSeries2216507$getInstrumentSpecification.getValue(Unknown
Source)
at
org.drools.base.ClassFieldExtractor.getValue(ClassFieldExtractor.java:127)
at org.drools.rule.Declaration.getValue(Declaration.java:197)
at
sequitem.quanteq.ruleflow.Rule_Create_Order_Limit_0ConsequenceInvoker.evaluate(Rule_Create_Order_Limit_0ConsequenceInvoker.java:17)
at
org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:550)
at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:514)
at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:462)
at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:424)
at
sequitem.quanteq.rules.engine.StatefulEngine.execute(StatefulEngine.java:50)
at
sequitem.quanteq.rules.engine.StatefulEngine.execute(StatefulEngine.java:24)
at
sequitem.quanteq.rules.RandomMarketEntryRulesTest.testRandomMarketEntryRules(RandomMarketEntryRulesTest.java:55)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at junit.framework.TestCase.runTest(TestCase.java:168)
at junit.framework.TestCase.runBare(TestCase.java:134)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at junit.textui.TestRunner.doRun(TestRunner.java:116)
at junit.textui.TestRunner.doRun(TestRunner.java:109)
at junit.textui.TestRunner.run(TestRunner.java:77)
at junit.textui.TestRunner.run(TestRunner.java:62)
at
sequitem.quanteq.rules.RandomMarketEntryRulesTest.main(RandomMarketEntryRulesTest.java:63)
E
Time: 36.687
There was 1 error:
1)
testRandomMarketEntryRules(sequitem.quanteq.rules.RandomMarketEntryRulesTest)org.drools.spi.ConsequenceException:
java.lang.NullPointerException
at
org.drools.base.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:14)
at
org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:553)
at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:514)
at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:462)
at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:424)
at
sequitem.quanteq.rules.engine.StatefulEngine.execute(StatefulEngine.java:50)
at
sequitem.quanteq.rules.engine.StatefulEngine.execute(StatefulEngine.java:24)
at
sequitem.quanteq.rules.RandomMarketEntryRulesTest.testRandomMarketEntryRules(RandomMarketEntryRulesTest.java:55)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at
sequitem.quanteq.rules.RandomMarketEntryRulesTest.main(RandomMarketEntryRulesTest.java:63)
Caused by: java.lang.NullPointerException
at
org.activequant.core.domainmodel.TimeSeries.getInstrumentSpecification(Unknown
Source)
at
org.drools.base.org.activequant.core.domainmodel.CandleSeries2216507$getInstrumentSpecification.getValue(Unknown
Source)
at
org.drools.base.ClassFieldExtractor.getValue(ClassFieldExtractor.java:127)
at org.drools.rule.Declaration.getValue(Declaration.java:197)
at
sequitem.quanteq.ruleflow.Rule_Create_Order_Limit_0ConsequenceInvoker.evaluate(Rule_Create_Order_Limit_0ConsequenceInvoker.java:17)
at
org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:550)
... 23 more
16 years, 11 months
StatefullSession or Stateless Session
by Blair Christie
I am new to to rules 4.03 and wondered in what cases
should a statefullSession be used and in what cases a
statelessSession be used? How do you decide?
____________________________________________________________________________________
Never miss a thing. Make Yahoo your home page.
http://www.yahoo.com/r/hs
16 years, 11 months
Re: The "Object" field in the DSL IDE Editor
by mmquelo massi
Sorry Guys.... But I do not see what "OBJECT" stand for in the DSL Editor?
I guess is something really simple but I dunno what!!
Is there anything in the DSL component that allows the user
to refer to a fact that I asserted somewhere else?
Is "Object" something like that?
Massi
16 years, 11 months
Re: Can't figure out the right syntax for this rule
by Henry Canterburry
I also tried the following rule syntax with from but without collect ( ) :
rule "Explode Globals"
ruleflow-group "Data Prep"
when
$market : Market() from request.requestObjects.values
$series : CandleSeries() from $market.candleSeries
then
insert ( $series );
insert ( $market );
end
At runtime I get an exception: org.mvel.PropertyAccessException: unable
to resolve property: values
16 years, 11 months
Collect Function
by Ronald R. DiFrango
All,
I have the following rule which uses the collect function:
rule "Invalid RR Line"
salience 100
when
rrDetailLine : DetailLine(detailKeyRecNo:keyRecNo != null,
lineNumber != null )
rrHeader : ArrayList( size == 0 ) from collect(RrHeader( keyRecNo !=
detailKeyRecNo ))
then
// logger.debug("Invalid RR Line: " + rrHeader.size());
logger.debug("Invalid RR Line: " + rrDetailLine.getKeyRecNo());
logger.debug("Invalid RR Line: " + rrDetailLine.getLineNumber());
drools.halt();
end
What I am seeing is that if I only have 1 RrHeader in working memory this
rule fails. Th reason I know that there is an RrHeader object is that I
change the rule to the following:
rule "Invalid RR Line"
salience 100
when
rrDetailLine : DetailLine(detailKeyRecNo:keyRecNo != null,
lineNumber != null )
rrHeader : RrHeader( keyRecNo != detailKeyRecNo )
then
// logger.debug("Invalid RR Line: " + rrHeader.size());
logger.debug("Invalid RR Line: " + rrDetailLine.getKeyRecNo());
logger.debug("Invalid RR Line: " + rrDetailLine.getLineNumber());
drools.halt();
end
And it worked just fine.
Thoughts?
Ron
16 years, 11 months
Can't figure out the right syntax for this rule
by Henry Canterburry
Hi All,
I am trying to figure out how to do a pattern match against a collection
and an array. Here is one of the domain model classes:
public class DecisionRequest extends Payload {
public void addRequestObject(String key, Object value){
this.payload.put(key, value);
}
public Object getRequestObject(String key){
return this.payload.get(key);
}
* public Map<String, Object> getRequestObjects(){
return Collections.unmodifiableMap(this.payload);
}*
}
Here is my rule code for now trying to access the values in the Map
returned by *public Map<String, Object> getRequestObjects(). As you can
see, getRequestObjects does not have a setter so it isn't recognized a a
javabean property. I have tried eval etc...*
global DecisionRequest request;
global DecisionResponse response;
rule "Explode Globals"
ruleflow-group "Data Prep"
when
$market : Market() from collect( request.requestsObjects.values
)* << property values isn't recognized? (expecting type LEFT_PARENT,
mismatched token error)
*$series : CandleSeries () from collect ( $market.candleSeries
)* << candleSeries returns a CandleSeries[] (expecting type
RIGHT_PARENT, mismatched token error)
* then
insert ( $series );
insert ( $market );
end
What would be the right way to pattern match against these values?
Thanks for any help
HC
16 years, 11 months
How to write constraint about a Map inside a Map?
by Felipe Piccolini
Suppouse I have a Map attribute and one of the values is another
Map...how can I check a member of the inner Map?
class MyFact{
Map map;
public MyFact(){
this.map = new HashMap();
}
....setter and getter...
}
-- test --
MyFact myFact = new MyFact();
Map innerMap = new HashMap();
innerMap.put("innerKey", new String("InnerValue"));
Map map = new HashMap();
map.put("mapKey", innerMap);
myFact.setMap(map);
.... set the RuleBase and insert myFact as a fact for the
WorkingMemory...
-------
Now... how should I write the rule to check the innerKey ??
rule "test InnerMap"
when
$mf: MyFact( map['mapKey']['innerKey'] ==
"InnerValue" ) // doesnt work...
....
$mf: MyFact( map['mapKey'].this['innerKey'] ==
"InnerValue" ) // doesnt work...
$mf: MyFact( map['mapKey'].['innerKey'] == "InnerValue" ) //
doesnt work...
$mf: MyFact( $innerMap: map['mapKey'], $innerMap['innerKey'] ==
"InnerValue" ) // doesnt work...
$mf: MyFact( $innerMap: map['mapKey'] -> ($innerMap
['innerKey'] == "InnerValue" )) // doesnt work...
Thanks.
Felipe Piccolini M.
felipe.piccolini(a)bluesoft.cl
16 years, 11 months