Uploaded image for project: 'JBRULES'
  1. JBRULES
  2. JBRULES-3685

NullPointerException in DefaultConsequenceInvoker at evaluate()

    Details

    • Type: Bug
    • Status: Resolved (View Workflow)
    • Priority: Major
    • Resolution: Cannot Reproduce
    • Affects Version/s: 5.1.1.FINAL
    • Fix Version/s: None
    • Component/s: drools-core (expert)
    • Labels:
      None

      Description

      i have a rule that looks like this:

      rule "bad node status"
      
      when
         $ruleIdString1 : [get from somewhere]
         $node1 : Node($idString1 : idString)
         $hostStatus1 : HostStatus($status1 : status , nodeIdString == $idString1 , status != "up") from entry-point "Event Stream"
      then
         Map alertParams = new HashMap();
         alertParams.put("0",($status1));
         Map reportParams = null;
         Map reportFieldValues = null;
         String component = null;
         alerts.issueAlert($idString1 , UUID.fromString($ruleIdString1) , alertParams , reportParams, reportFieldValues, component);
      end
      

      this causes drools to generate a class by the name of Rule_Bad_Node_Status_0DefaultConsequenceInvoker.java with the following bit of code:

          public void evaluate(org.drools.spi.KnowledgeHelper knowledgeHelper,
                               org.drools.WorkingMemory workingMemory) throws Exception {
      
              org.drools.spi.Tuple tuple = knowledgeHelper.getTuple();
              org.drools.rule.Declaration[] declarations = knowledgeHelper.getRule().getDeclarations();
      
              
                org.drools.common.InternalFactHandle $ruleIdString1__Handle__ = ( org.drools.common.InternalFactHandle ) tuple.get( knowledgeHelper.getDeclaration( declarations[1].getIdentifier() ) );
                java.lang.String $ruleIdString1 = ( java.lang.String )  declarations[1].getValue((org.drools.common.InternalWorkingMemory) workingMemory, $ruleIdString1__Handle__.getObject() );
                $ruleIdString1__Handle__ =  (org.drools.common.InternalFactHandle) knowledgeHelper.getWorkingMemory().getFactHandle( $ruleIdString1 );
                knowledgeHelper.getIdentityMap().put($ruleIdString1, $ruleIdString1__Handle__ );
              
                org.drools.common.InternalFactHandle $idString2__Handle__ = ( org.drools.common.InternalFactHandle ) tuple.get( knowledgeHelper.getDeclaration( declarations[3].getIdentifier() ) );
                java.lang.String $idString2 = ( java.lang.String )  declarations[3].getValue((org.drools.common.InternalWorkingMemory) workingMemory, $idString2__Handle__.getObject() );
                $idString2__Handle__ =  (org.drools.common.InternalFactHandle) knowledgeHelper.getWorkingMemory().getFactHandle( $idString2 );
                knowledgeHelper.getIdentityMap().put($idString2, $idString2__Handle__ );
              
                org.drools.common.InternalFactHandle $status1__Handle__ = ( org.drools.common.InternalFactHandle ) tuple.get( knowledgeHelper.getDeclaration( declarations[5].getIdentifier() ) );
                java.lang.String $status1 = ( java.lang.String )  declarations[5].getValue((org.drools.common.InternalWorkingMemory) workingMemory, $status1__Handle__.getObject() );
                $status1__Handle__ =  (org.drools.common.InternalFactHandle) knowledgeHelper.getWorkingMemory().getFactHandle( $status1 );      //NullPointerException here
                knowledgeHelper.getIdentityMap().put($status1, $status1__Handle__ );
              
      
               com.emc.dpa.analysis.Alerts alerts = ( com.emc.dpa.analysis.Alerts ) workingMemory.getGlobal( "alerts" );
              
      
              Rule_Bad_Node_Status_0.defaultConsequence (
                  knowledgeHelper,
                   $ruleIdString1, $ruleIdString1__Handle__
                  , $idString2, $idString2__Handle__
                  , $status1, $status1__Handle__
                  ,
      	         alerts
      	         );
          }
      

      if, for some reason, the value for HostStatus.status is null i get a NPE from the commented line in the above code. the stack trace looks like this:

      Caused by: java.lang.NullPointerException
      	at org.drools.common.EqualityAssertMapComparator.hashCodeOf(EqualityAssertMapComparator.java:48) [drools-core.jar:5.1.1]
      	at org.drools.core.util.ObjectHashMap.get(ObjectHashMap.java:100) [drools-core.jar:5.1.1]
      	at org.drools.common.SingleThreadedObjectStore.getHandleForObject(SingleThreadedObjectStore.java:122) [drools-core.jar:5.1.1]
      	at org.drools.common.AbstractWorkingMemory.getFactHandle(AbstractWorkingMemory.java:861) [drools-core.jar:5.1.1]
      	at [package].Rule_Bad_Node_Status_0DefaultConsequenceInvoker.evaluate(Rule_Bad_Node_Status_0DefaultConsequenceInvoker.java:33)
      	at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:917) [drools-core.jar:5.1.1]
      	... 101 more
      
      

      i think this is related to the line in the then section that reads "alertParams.put("0",($status1));" but i think putting null into a map should be possible.

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                mark.proctor Mark Proctor
                Reporter:
                hatchetman82 Radai Rosenblatt
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: