Details

    • Type: Bug
    • Status: Resolved (View Workflow)
    • Priority: Major
    • Resolution: Done
    • Affects Version/s: 5.4.0.Final
    • Fix Version/s: None
    • Component/s: drools-core (expert)
    • Labels:
      None

      Description

      Problem: When there are two rules (A and B) such that B extends A and both A and B reference the same fact in their conditions, calling update on that fact after calling fireAllRules causes a NPE.

      DRL:

      package inheritance
      
      import org.drools.Address
      
      rule "Parent"
      	enabled false
      	when
      		Address(suburb == "xyz")
      	then
      	
      end
      
      rule "Child" extends "Parent"
      	when
      		$addy:Address(street == "123 some street")
      		
      	then
      		System.out.println($addy);
      end
      

      Test:

      package org.drools.testframework;
      
      import org.drools.Address;
      import org.drools.KnowledgeBase;
      import org.drools.KnowledgeBaseFactory;
      import org.drools.builder.KnowledgeBuilder;
      import org.drools.builder.KnowledgeBuilderFactory;
      import org.drools.builder.ResourceType;
      import org.drools.io.Resource;
      import org.drools.io.ResourceFactory;
      import org.drools.runtime.StatefulKnowledgeSession;
      import org.drools.runtime.rule.FactHandle;
      import org.junit.Test;
      
      public class ExternalUpdateInheritanceTest {
      
      	@Test
      	public void testExternalInheritanceFactUpdates() {
      		KnowledgeBase knowledgeBase = null;
      
      		KnowledgeBuilder builder = KnowledgeBuilderFactory.newKnowledgeBuilder();
      
      		Resource newClassPathResource = ResourceFactory.newClassPathResource("org/drools/lang/inheritance.drl");
      		builder.add(newClassPathResource, ResourceType.DRL);
      
      		if (builder.hasErrors()) {
      			throw new RuntimeException(builder.getErrors().toString());
      		}
      		knowledgeBase = KnowledgeBaseFactory.newKnowledgeBase();
      		knowledgeBase.addKnowledgePackages(builder.getKnowledgePackages());
      		
      		StatefulKnowledgeSession ksession = knowledgeBase.newStatefulKnowledgeSession();
      		
      		Address address = new Address();
      		
      		address.setSuburb("xyz");
      		FactHandle addressHandle = ksession.insert(address);
      		
      		int rulesFired = ksession.fireAllRules();
      		
      		address.setStreet("123 some street");
      		
      		
      		ksession.update(addressHandle, address);
      		
      		System.out.println(rulesFired);
      	}
      }
      
      

      Stack Trace:
      java.lang.NullPointerException
      at org.drools.common.DefaultAgenda.createActivation(DefaultAgenda.java:572)
      at org.drools.reteoo.RuleTerminalNode.modifyLeftTuple(RuleTerminalNode.java:297)
      at org.drools.reteoo.LeftTupleSource.doModifyLeftTuple(LeftTupleSource.java:297)
      at org.drools.reteoo.AbstractTerminalNode.modifyLeftTuple(AbstractTerminalNode.java:104)
      at org.drools.reteoo.SingleLeftTupleSinkAdapter.doPropagateModifyLeftTuple(SingleLeftTupleSinkAdapter.java:205)
      at org.drools.reteoo.SingleLeftTupleSinkAdapter.propagateModifyObject(SingleLeftTupleSinkAdapter.java:235)
      at org.drools.reteoo.LeftInputAdapterNode.modifyObject(LeftInputAdapterNode.java:170)
      at org.drools.reteoo.SingleObjectSinkAdapter.propagateModifyObject(SingleObjectSinkAdapter.java:68)
      at org.drools.reteoo.AlphaNode.modifyObject(AlphaNode.java:157)
      at org.drools.reteoo.CompositeObjectSinkAdapter.doPropagateModifyObject(CompositeObjectSinkAdapter.java:507)
      at org.drools.reteoo.CompositeObjectSinkAdapter.propagateModifyObject(CompositeObjectSinkAdapter.java:421)
      at org.drools.reteoo.ObjectTypeNode.modifyObject(ObjectTypeNode.java:314)
      at org.drools.reteoo.EntryPointNode.modifyObject(EntryPointNode.java:265)
      at org.drools.common.NamedEntryPoint.update(NamedEntryPoint.java:474)
      at org.drools.common.AbstractWorkingMemory.update(AbstractWorkingMemory.java:960)
      at org.drools.common.AbstractWorkingMemory.update(AbstractWorkingMemory.java:933)
      at org.drools.impl.StatefulKnowledgeSessionImpl.update(StatefulKnowledgeSessionImpl.java:284)
      at org.drools.testframework.ExternalUpdateInheritanceTest.testExternalInheritanceFactUpdates(ExternalUpdateInheritanceTest.java:44)

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                mark.proctor Mark Proctor
                Reporter:
                bgraham Bobby Graham
              • Votes:
                2 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: