I am pretty sure this is a bug, but would like confirmation from people more familiar with the code base. My tests seem to show that RuleTerminalNode can cause an NPE on two different lines of code. Both places where a call is made to “workingMemory.getTruthMaintenanceSystem()” in that class can result in a null pointer exception if the “maintainTms” option is false. In my case I discovered the issue in some unit tests where I am calling “knowledgeBase.removeKnowledgePackage” which ends up (eventually) in RuleTerminalNode. I have pasted an example stack trace below:
 
Thread [main] (Suspended (exception NullPointerException))   
        RuleTerminalNode$RTNCleanupAdapter.cleanUp(LeftTuple, InternalWorkingMemory) line: 519     
        ObjectTypeNode.doRemove(RuleRemovalContext, ReteooBuilder, BaseNode, InternalWorkingMemory[]) line: 347    
        ObjectTypeNode.remove(RuleRemovalContext, ReteooBuilder, BaseNode, InternalWorkingMemory[]) line: 325    
        AlphaNode(ObjectSource).doRemove(RuleRemovalContext, ReteooBuilder, BaseNode, InternalWorkingMemory[]) line: 209    
        AlphaNode(BaseNode).remove(RuleRemovalContext, ReteooBuilder, BaseNode, InternalWorkingMemory[]) line: 109    
        LeftInputAdapterNode.doRemove(RuleRemovalContext, ReteooBuilder, BaseNode, InternalWorkingMemory[]) line: 187    
        LeftInputAdapterNode(BaseNode).remove(RuleRemovalContext, ReteooBuilder, BaseNode, InternalWorkingMemory[]) line: 109    
        RuleTerminalNode.doRemove(RuleRemovalContext, ReteooBuilder, BaseNode, InternalWorkingMemory[]) line: 411    
        RuleTerminalNode(BaseNode).remove(RuleRemovalContext, ReteooBuilder, BaseNode, InternalWorkingMemory[]) line: 109    
        ReteooBuilder.removeRule(Rule) line: 237      
        ReteooRuleBase.removeRule(Rule) line: 432     
        ReteooRuleBase(AbstractRuleBase).removeRule(Package, Rule) line: 831 
        ReteooRuleBase(AbstractRuleBase).removePackage(String) line: 751     
        KnowledgeBaseImpl.removeKnowledgePackage(String) line: 201   

 

(I redacted the stack after the call to removeKnowledgePackage() because it provides no value in this discussion)

 

I am using Drools 5.1.1. I have also looked at the latest version of the code here:

 

https://github.com/droolsjbpm/droolsjbpm/blob/master/drools-core/src/main/java/org/drools/reteoo/RuleTerminalNode.java

 

Can anyone confirm that this is a bug, or if not tell me what I am doing wrong?

 

 

Thank You,

Nathan Bell