Henry,

   This is tricky. Can you please open a JIRA for it? I will take a look as soon as I can on how to fix that.

   Meanwhile, the workaround is: instead of inheriting from a collection class, can you wrap it instead?

public class NamedCollection<T> {
   private String name;
   private LinkedList<T> list;

   // constructor, getters, setters
}

   This change will make it work for you.

    []s
    Edson

2008/1/15, Henry Canterburry <canterburry@gmail.com>:
I am having the same problem as described in this post:
http://www.nabble.com/The-effect-of-not-using-shadow-facts-tp11652637p11708600.html

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
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users



--
  Edson Tirelli
  JBoss Drools Core Development
  Office: +55 11 3529-6000
  Mobile: +55 11 9287-5646
  JBoss, a division of Red Hat @ www.jboss.com