title: Drools: rule not fired (Possible bug when using registered customized operator)
body: <p>I just started to use Drools (7.1.0 Beta &amp; 7.0.0 FINAL), and wanted to apply two rules based on Soundex approximate algorithm (new customized registered function)</p>
  
  <p>I run the following code with the 3 contact facts  against 4 suspect facts:</p>
  
  <pre><code>    KieServices ks = KieServices.Factory.get();
  KieHelper kh = new KieHelper() ;
  KieModuleModel kmm = ks.newKieModuleModel();
  kmm.setConfigurationProperty("drools.evaluator.soundex", SoundexEvaluatorsDefinition.class.getName());
  kh.setKieModuleModel(kmm);
  kh.addResource(ResourceFactory.newClassPathResource("soundex_m1"
      + ".drl",SoundexProofConceptExample.class),ResourceType.DRL ) ;
  KieBase kb =kh.build();
  AgendaEventListener ael = new DebugAgendaEventListener();
  
  KieSession ksession =kb.newKieSession();
  
  ksession.addEventListener(ael);
  //StatelessKieSession ksession =kb.newStatelessKieSession();
  
  long totalTime = 0;
  
  String filename;
  if ( args.length != 0 ) {
      String arg = args[0];
      filename = arg;
  } else {
      filename = "soundex2.dat";
  }
  
  InputStream is = SoundexProofConceptExample.class.getResourceAsStream( "data/" + filename );
  List&lt;Suspect&gt; list = getInputObjects( is );
  for ( Iterator&lt;Suspect&gt; it = list.iterator(); it.hasNext(); ) {
          Object object = it.next();
          ksession.insert( object );
  }
  
  
  ksession.insert( new Contact( "MIELI","GIOVANI",56 ));
  ksession.insert( new Contact( "AMONE","DAVID",46 ));
  ksession.insert( new Contact( "MOKKY","DANIEL",48 ));
  
  long start = System.currentTimeMillis();
  //ksession.fireAllRules();
  ksession.fireAllRules();
  </code></pre>
  
  <p>The suspect facts within the file are:</p>
  
  <pre><code>(Suspect (fistname AMONE) (lastname DAVI)  (age  46) (reason criminel) )
  (Suspect (fistname AMONE) (lastname DAVID) (age  46) (reason criminel) )
  (Suspect (fistname PAIS) (lastname JULES)   (age  35) (reason escrow) )
  (Suspect (fistname MOKY) (lastname DANO)   (age  35) (reason terroriste) )
  </code></pre>
  
  <p>With the following two rules:</p>
  
  <pre><code>rule "Rule 01 - soundex[m1,20] " salience 50
      when
          $suspect : Suspect( $s_firstname : firstname)
          //$suspect : Suspect( )
          $contact :  Contact(firstname soundex[m1,20] $suspect.firstname &amp;&amp;  lastname soundex[m1,20] $suspect.lastname)
  
     then
          retract($contact)
          System.out.println("!!!RESULT: Contact: "+ $contact + " match suspect: " + $suspect + " drools : " + org.drools.examples.soundex.Utility.displayRule(drools));
  end
  rule "Rule 02 - soundex[m1,50] " salience 20
      when
           $suspect : Suspect($s_lastname: lastname)
           //$suspect : Suspect( )
           $contact :  Contact(firstname soundex[m1,50] $suspect.firstname &amp;&amp; lastname soundex[m1,50] $suspect.lastname)
  
     then
          System.out.println("!!!RESULT Contact: "+ $contact + " match suspect: " + $suspect + " drools : " + org.drools.examples.soundex.Utility.displayRule(drools));
  End
  </code></pre>
  
  <p>And I get to <strong>expected</strong> following output:</p>
  
  <blockquote>
    <p>17:35:51.888 [main] INFO 
    o.d.c.k.b.impl.KieRepositoryImpl.addKieModule:119 - KieModule was
    added: MemoryKieModule[releaseId=org.default:artifact:1.0.0-SNAPSHOT]
    MIELI[M400] doesnt match[m1,20]AMONE[A550] 17:35:52.251 [main] INFO 
    o.d.c.event.DebugAgendaEventListener.matchCreated:39 -
    ==>[ActivationCreatedEvent: getActivation()=[[ Rule 01 - soundex[m1,20]  active=false ] [ [fact
    0:6:1992801971:2009445466:6:DEFAULT:NON_TRAIT:org.drools.examples.soundex.Contact:Person{lastname='DAVID',firstname='AMONE',
    age=46}] [fact
    0:2:788892554:2009445466:2:DEFAULT:NON_TRAIT:org.drools.examples.soundex.Suspect:Person{lastname='DAVID',firstname='AMONE',
    age=46,reason='criminel'}] ] ], getKnowledgeRuntime()=KieSession[0]]
    17:35:52.252 [main] INFO 
    o.d.c.event.DebugAgendaEventListener.beforeMatchFired:47 -
    ==>[BeforeActivationFiredEvent:  getActivation()=[[ Rule 01 - soundex[m1,20]  active=false ] [ [fact
    0:6:1992801971:2009445466:6:DEFAULT:NON_TRAIT:org.drools.examples.soundex.Contact:Person{lastname='DAVID',firstname='AMONE',
    age=46}] [fact
    0:2:788892554:2009445466:2:DEFAULT:NON_TRAIT:org.drools.examples.soundex.Suspect:Person{lastname='DAVID',firstname='AMONE',
    age=46,reason='criminel'}] ] ], getKnowledgeRuntime()=KieSession[0]]
    !!!RESULT: Contact: Person{lastname='DAVID',firstname='AMONE', age=46}
    match suspect: Person{lastname='DAVID',firstname='AMONE',
    age=46,reason='criminel'} drools :  rule triggered: Rule 01 -
    soundex[m1,20]  17:35:52.257 [main] INFO 
    o.d.c.event.DebugAgendaEventListener.afterMatchFired:51 -
    ==>[AfterActivationFiredEvent: getActivation()=[[ Rule 01 - soundex[m1,20]  active=false ] [ [fact
    0:6:1992801971:2009445466:6:DEFAULT:NON_TRAIT:org.drools.examples.soundex.Contact:Person{lastname='DAVID',firstname='AMONE',
    age=46}] [fact
    0:2:788892554:2009445466:2:DEFAULT:NON_TRAIT:org.drools.examples.soundex.Suspect:Person{lastname='DAVID',firstname='AMONE',
    age=46,reason='criminel'}] ] ], getKnowledgeRuntime()=KieSession[0]]
    17:35:52.261 [main] INFO 
    o.d.c.event.DebugAgendaEventListener.matchCreated:39 -
    ==>[ActivationCreatedEvent: getActivation()=[[ Rule 02 - soundex[m1,50]  active=false ] [ [fact
    0:7:1681094402:-2139086223:7:DEFAULT:NON_TRAIT:org.drools.examples.soundex.Contact:Person{lastname='DANIEL',firstname='MOKKY',
    age=48}] [fact
    0:4:1060042118:64813285:4:DEFAULT:NON_TRAIT:org.drools.examples.soundex.Suspect:Person{lastname='DANO',firstname='MOKY',
    age=35,reason='terroriste'}] ] ], getKnowledgeRuntime()=KieSession[0]]
    17:35:52.261 [main] INFO 
    o.d.c.event.DebugAgendaEventListener.beforeMatchFired:47 -
    ==>[BeforeActivationFiredEvent:  getActivation()=[[ Rule 02 - soundex[m1,50]  active=false ] [ [fact
    0:7:1681094402:-2139086223:7:DEFAULT:NON_TRAIT:org.drools.examples.soundex.Contact:Person{lastname='DANIEL',firstname='MOKKY',
    age=48}] [fact
    0:4:1060042118:64813285:4:DEFAULT:NON_TRAIT:org.drools.examples.soundex.Suspect:Person{lastname='DANO',firstname='MOKY',
    age=35,reason='terroriste'}] ] ], getKnowledgeRuntime()=KieSession[0]]
    !!!RESULT Contact: Person{lastname='DANIEL',firstname='MOKKY', age=48}
    match suspect: Person{lastname='DANO',firstname='MOKY',
    age=35,reason='terroriste'} drools :  rule triggered: Rule 02 -
    soundex[m1,50]  17:35:52.263 [main] INFO 
    o.d.c.event.DebugAgendaEventListener.afterMatchFired:51 -
    ==>[AfterActivationFiredEvent: getActivation()=[[ Rule 02 - soundex[m1,50]  active=false ] [ [fact
    0:7:1681094402:-2139086223:7:DEFAULT:NON_TRAIT:org.drools.examples.soundex.Contact:Person{lastname='DANIEL',firstname='MOKKY',
    age=48}] [fact
    0:4:1060042118:64813285:4:DEFAULT:NON_TRAIT:org.drools.examples.soundex.Suspect:Person{lastname='DANO',firstname='MOKY',
    age=35,reason='terroriste'}] ] ], getKnowledgeRuntime()=KieSession[0]]</p>
  </blockquote>
  
  <p>Now If I change slightly the rules </p>
  
  <pre><code>rule "Rule 01 - soundex[m1,20] KO " salience 50
      when
          //$suspect : Suspect( $s_firstname : firstname)
          $suspect : Suspect()
          $contact :  Contact(firstname soundex[m1,20] $suspect.firstname &amp;&amp;  lastname soundex[m1,20] $suspect.lastname)
  
     then
          //retract($contact)
          System.out.println("!!!RESULT: Contact: "+ $contact + " match suspect: " + $suspect + " drools : " + org.drools.examples.soundex.Utility.displayRule(drools));
  end
  rule "Rule 02 - soundex[m1,50] KO" salience 20
      when
           //$suspect : Suspect()
           $suspect : Suspect()
           $contact :  Contact(firstname soundex[m1,50] $suspect.firstname &amp;&amp; lastname soundex[m1,50] $suspect.lastname)
  
     then
          System.out.println("!!!RESULT Contact: "+ $contact + " match suspect: " + $suspect + " drools : " + org.drools.examples.soundex.Utility.displayRule(drools));
  end
  </code></pre>
  
  <p>It seems that rule 02 is never triggered as you can see bellow</p>
  
  <blockquote>
    <p>4:56:22.534 [main] INFO 
    o.d.c.event.DebugAgendaEventListener.matchCreated:39 -
    ==>[ActivationCreatedEvent: getActivation()=[[ Rule 01 - soundex[m1,20] KO  active=false ] [ [fact
    0:6:1387620926:2009445466:6:DEFAULT:NON_TRAIT:org.drools.examples.soundex.Contact:Person{lastname='DAVID',firstname='AMONE',
    age=46}] [fact
    0:2:1971152916:2009445466:2:DEFAULT:NON_TRAIT:org.drools.examples.soundex.Suspect:Person{lastname='DAVID',firstname='AMONE',
    age=46,reason='criminel'}] ] ], getKnowledgeRuntime()=KieSession[0]]
    14:56:22.534 [main] INFO 
    o.d.c.event.DebugAgendaEventListener.beforeMatchFired:47 -
    ==>[BeforeActivationFiredEvent:  getActivation()=[[ Rule 01 - soundex[m1,20] KO  active=false ] [ [fact
    0:6:1387620926:2009445466:6:DEFAULT:NON_TRAIT:org.drools.examples.soundex.Contact:Person{lastname='DAVID',firstname='AMONE',
    age=46}] [fact
    0:2:1971152916:2009445466:2:DEFAULT:NON_TRAIT:org.drools.examples.soundex.Suspect:Person{lastname='DAVID',firstname='AMONE',
    age=46,reason='criminel'}] ] ], getKnowledgeRuntime()=KieSession[0]]
    !!!RESULT: Contact: Person{lastname='DAVID',firstname='AMONE', age=46}
    match suspect: Person{lastname='DAVID',firstname='AMONE',
    age=46,reason='criminel'} drools :  rule triggered: Rule 01 -
    soundex[m1,20] KO  14:56:22.539 [main] INFO 
    o.d.c.event.DebugAgendaEventListener.afterMatchFired:51 -
    ==>[AfterActivationFiredEvent: getActivation()=[[ Rule 01 - soundex[m1,20] KO  active=false ] [ [fact
    0:6:1387620926:2009445466:6:DEFAULT:NON_TRAIT:org.drools.examples.soundex.Contact:Person{lastname='DAVID',firstname='AMONE',
    age=46}] [fact
    0:2:1971152916:2009445466:2:DEFAULT:NON_TRAIT:org.drools.examples.soundex.Suspect:Person{lastname='DAVID',firstname='AMONE',
    age=46,reason='criminel'}] ] ], getKnowledgeRuntime()=KieSession[0]]
    14:56:22.540 [main] INFO 
    o.d.c.event.DebugAgendaEventListener.matchCreated:39 -
    ==>[ActivationCreatedEvent: getActivation()=[[ Rule 02 - soundex[m1,50] KO active=false ] [ [fact
    0:6:1387620926:2009445466:6:DEFAULT:NON_TRAIT:org.drools.examples.soundex.Contact:Person{lastname='DAVID',firstname='AMONE',
    age=46}] [fact
    0:2:1971152916:2009445466:2:DEFAULT:NON_TRAIT:org.drools.examples.soundex.Suspect:Person{lastname='DAVID',firstname='AMONE',
    age=46,reason='criminel'}] ] ], getKnowledgeRuntime()=KieSession[0]]
    14:56:22.540 [main] INFO 
    o.d.c.event.DebugAgendaEventListener.beforeMatchFired:47 -
    ==>[BeforeActivationFiredEvent:  getActivation()=[[ Rule 02 - soundex[m1,50] KO active=false ] [ [fact
    0:6:1387620926:2009445466:6:DEFAULT:NON_TRAIT:org.drools.examples.soundex.Contact:Person{lastname='DAVID',firstname='AMONE',
    age=46}] [fact
    0:2:1971152916:2009445466:2:DEFAULT:NON_TRAIT:org.drools.examples.soundex.Suspect:Person{lastname='DAVID',firstname='AMONE',
    age=46,reason='criminel'}] ] ], getKnowledgeRuntime()=KieSession[0]]
    !!!RESULT Contact: Person{lastname='DAVID',firstname='AMONE', age=46}
    match suspect: Person{lastname='DAVID',firstname='AMONE',
    age=46,reason='criminel'} drools :  rule triggered: Rule 02 -
    soundex[m1,50] KO 14:56:22.541 [main] INFO 
    o.d.c.event.DebugAgendaEventListener.afterMatchFired:51 -
    ==>[AfterActivationFiredEvent: getActivation()=[[ Rule 02 - soundex[m1,50] KO active=false ] [ [fact
    0:6:1387620926:2009445466:6:DEFAULT:NON_TRAIT:org.drools.examples.soundex.Contact:Person{lastname='DAVID',firstname='AMONE',
    age=46}] [fact
    0:2:1971152916:2009445466:2:DEFAULT:NON_TRAIT:org.drools.examples.soundex.Suspect:Person{lastname='DAVID',firstname='AMONE',
    age=46,reason='criminel'}] ] ], getKnowledgeRuntime()=KieSession[0]]`</p>
  </blockquote>
  
  <p>It seems that something is not reinitialized/rewinded when the suspect pickup declaration is identical?</p>
  
  <p>Now I did the same kind of test but this time with “standard” operator like soundslike or even == and I everythin is ok and I don’t have to pickup suspect with a difference synthax:</p>
  
  <p>Here are the “standard” rules:</p>
  
  <p>A)</p>
  
  <pre><code> import org.drools.examples.bug.Person;
      import org.drools.examples.bug.Suspect;
  
  
      rule "Rule 01 - firstname and lastname"
          when
              $suspect : Suspect()
              //$suspect : Suspect( $s_firstname : firstname, $s_lastname : lastname)
              $contact :  Contact(firstname soundslike $suspect.firstname &amp;&amp; lastname soundslike $suspect.lastname)
  
         then
              retract($contact)
              System.out.println("!!!RESULT: Contact: "+ $contact + " match suspect: "  + " drools : Rule 01 - firstname and lastname");
      end
      rule "Rule 02 - firstname or lastname"
          when
               //$suspect : Suspect( $s_firstname : firstname, $s_lastname : lastname)
               $suspect : Suspect()
               $contact :  Contact(firstname soundslike $suspect.firstname || lastname soundslike $suspect.lastname)
  
         then
              System.out.println("!!!RESULT Contact: "+ $contact + " match suspect: " + $suspect + " drools : Rule 02 - firstname or lastname");
      End
  </code></pre>
  
  <p>B)</p>
  
  <pre><code>import org.drools.examples.bug.Person;
  import org.drools.examples.bug.Suspect;
  
  
  rule "Rule 01 - firstname and lastname"
      when
          $suspect : Suspect()
          //$suspect : Suspect( $s_firstname : firstname, $s_lastname : lastname)
          $contact :  Contact(firstname == $suspect.firstname &amp;&amp; lastname == $suspect.lastname)
  
     then
          retract($contact)
          System.out.println("!!!RESULT: Contact: "+ $contact + " match suspect: "  + " drools : Rule 01 - firstname and lastname");
  end
  rule "Rule 02 - firstname or lastname"
      when
           //$suspect : Suspect( $s_firstname : firstname, $s_lastname : lastname)
           $suspect : Suspect()
           $contact :  Contact(firstname == $suspect.firstname || lastname == $suspect.lastname)
  
     then
          System.out.println("!!!RESULT Contact: "+ $contact + " match suspect: " + $suspect + " drools : Rule 02 - firstname or lastname");
  end
  </code></pre>
  
  <p>I run the following code:</p>
  
  <pre><code>KieServices ks = KieServices.Factory.get();
      KieHelper kh = new KieHelper() ;
      KieModuleModel kmm = ks.newKieModuleModel();
      kh.setKieModuleModel(kmm);
      kh.addResource(ResourceFactory.newClassPathResource("Bug1"
          + ".drl",Bug1.class),ResourceType.DRL ) ;
      KieBase kb =kh.build();
      AgendaEventListener ael = new DebugAgendaEventListener();
  
      KieSession ksession =kb.newKieSession();
  
      ksession.addEventListener(ael);
  
      long totalTime = 0;
  
  
      ksession.insert(new Suspect("AMONE","DAVI",46,"C1"));
      ksession.insert(new Suspect("PAIS","JULES",35,"C2"));
      ksession.insert(new Suspect("MOKKY","DANO",35,"C1"));
      ksession.insert(new Suspect("AMONE","DAVID",46,"C3"));
  
  
      ksession.insert( new Contact( "MIELI","GIOVANI",56 ));
      ksession.insert( new Contact( "AMONE","DAVID",46 ));
      ksession.insert( new Contact( "MOKKY","DANIEL",48 ));
  
  
      long start = System.currentTimeMillis();
      ksession.fireAllRules();
  </code></pre>
  
  <p>Everything’s seems to be ok even if I change the syntax to pick up the suspect fact as I did for the earlier example with my customized operator.</p>
  
  <blockquote>
    <p>10:33:05.061 [main] INFO 
    o.d.c.k.b.impl.KieRepositoryImpl.addKieModule:119 - KieModule was
    added: MemoryKieModule[releaseId=org.default:artifact:1.0.0-SNAPSHOT]
    10:33:05.434 [main] INFO 
    o.d.c.event.DebugAgendaEventListener.matchCreated:39 -
    ==>[ActivationCreatedEvent: getActivation()=[[ Rule 01 - firstname and lastname active=false ] [ [fact
    0:6:413373997:2009445466:6:DEFAULT:NON_TRAIT:org.drools.examples.bug.Contact:Person{lastname='DAVID',firstname='AMONE',
    age=46}] [fact
    0:4:1380976928:2009445466:4:DEFAULT:NON_TRAIT:org.drools.examples.bug.Suspect:Person{lastname='DAVID',firstname='AMONE',
    age=46,reason='C3'}] ] ], getKnowledgeRuntime()=KieSession[0]]
    10:33:05.435 [main] INFO 
    o.d.c.event.DebugAgendaEventListener.beforeMatchFired:47 -
    ==>[BeforeActivationFiredEvent:  getActivation()=[[ Rule 01 - firstname and lastname active=false ] [ [fact
    0:6:413373997:2009445466:6:DEFAULT:NON_TRAIT:org.drools.examples.bug.Contact:Person{lastname='DAVID',firstname='AMONE',
    age=46}] [fact
    0:4:1380976928:2009445466:4:DEFAULT:NON_TRAIT:org.drools.examples.bug.Suspect:Person{lastname='DAVID',firstname='AMONE',
    age=46,reason='C3'}] ] ], getKnowledgeRuntime()=KieSession[0]]
    !!!RESULT: Contact: Person{lastname='DAVID',firstname='AMONE', age=46}
    match suspect:  drools : Rule 01 - firstname and lastname 10:33:05.441
    [main] INFO  o.d.c.event.DebugAgendaEventListener.afterMatchFired:51 -
    ==>[AfterActivationFiredEvent: getActivation()=[[ Rule 01 - firstname and lastname active=false ] [ [fact
    0:6:413373997:2009445466:6:DEFAULT:NON_TRAIT:org.drools.examples.bug.Contact:Person{lastname='DAVID',firstname='AMONE',
    age=46}] [fact
    0:4:1380976928:2009445466:4:DEFAULT:NON_TRAIT:org.drools.examples.bug.Suspect:Person{lastname='DAVID',firstname='AMONE',
    age=46,reason='C3'}] ] ], getKnowledgeRuntime()=KieSession[0]]
    10:33:05.469 [main] INFO 
    o.d.c.event.DebugAgendaEventListener.matchCreated:39 -
    ==>[ActivationCreatedEvent: getActivation()=[[ Rule 02 - firstname or lastname active=false ] [ [fact
    0:7:2024711353:-2139086223:7:DEFAULT:NON_TRAIT:org.drools.examples.bug.Contact:Person{lastname='DANIEL',firstname='MOKKY',
    age=48}] [fact
    0:3:1032568028:64813285:3:DEFAULT:NON_TRAIT:org.drools.examples.bug.Suspect:Person{lastname='DANO',firstname='MOKKY',
    age=35,reason='C1'}] ] ], getKnowledgeRuntime()=KieSession[0]]
    10:33:05.469 [main] INFO 
    o.d.c.event.DebugAgendaEventListener.beforeMatchFired:47 -
    ==>[BeforeActivationFiredEvent:  getActivation()=[[ Rule 02 - firstname or lastname active=false ] [ [fact
    0:7:2024711353:-2139086223:7:DEFAULT:NON_TRAIT:org.drools.examples.bug.Contact:Person{lastname='DANIEL',firstname='MOKKY',
    age=48}] [fact
    0:3:1032568028:64813285:3:DEFAULT:NON_TRAIT:org.drools.examples.bug.Suspect:Person{lastname='DANO',firstname='MOKKY',
    age=35,reason='C1'}] ] ], getKnowledgeRuntime()=KieSession[0]]
    !!!RESULT Contact: Person{lastname='DANIEL',firstname='MOKKY', age=48}
    match suspect: Person{lastname='DANO',firstname='MOKKY',
    age=35,reason='C1'} drools : Rule 02 - firstname or lastname
    10:33:05.471 [main] INFO 
    o.d.c.event.DebugAgendaEventListener.afterMatchFired:51 -
    ==>[AfterActivationFiredEvent: getActivation()=[[ Rule 02 - firstname or lastname active=false ] [ [fact
    0:7:2024711353:-2139086223:7:DEFAULT:NON_TRAIT:org.drools.examples.bug.Contact:Person{lastname='DANIEL',firstname='MOKKY',
    age=48}] [fact
    0:3:1032568028:64813285:3:DEFAULT:NON_TRAIT:org.drools.examples.bug.Suspect:Person{lastname='DANO',firstname='MOKKY',
    age=35,reason='C1'}] ] ], getKnowledgeRuntime()=KieSession[0]]</p>
  </blockquote>
  
  <p>thx for your findings/help/answers</p>