<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">Confirmed as a race condition,
      hopefully it will be fixed in 5.6<br>
      Thanks Jason and Wolfgang<br>
      Davide<br>
      <br>
      On 05/14/2013 06:43 AM, Jason Barto wrote:<br>
    </div>
    <blockquote
cite="mid:CAApekVeRNvFAssoBVk2vnb4tCUgDa2jgCegvDGZ8TF8229AFog@mail.gmail.com"
      type="cite">
      <p>Thanks Wolfgang. I'll change over to the 5.3 libraries and
        carry on with my testing. I'll also enter this issue into jira
        if it doesn't yet exist. </p>
      <p>Sincerely, <br>
        Jason </p>
      <div class="gmail_quote">On May 14, 2013 11:30 AM, "Wolfgang Laun"
        &lt;<a moz-do-not-send="true"
          href="mailto:wolfgang.laun@gmail.com">wolfgang.laun@gmail.com</a>&gt;
        wrote:<br type="attribution">
        <blockquote class="gmail_quote" style="margin:0 0 0
          .8ex;border-left:1px #ccc solid;padding-left:1ex">
          Looks like a bug in Drools to me. It has the classic hallmark
          of a<br>
          race condition: the NPE does not happen with every run (on my
          system),<br>
          perhaps only with 85%.<br>
          <br>
          Moreover, with 5.4.0 I get a similar NPE and also:<br>
          Exception in thread "main" java.util.NoSuchElementException<br>
          &nbsp; &nbsp; &nbsp; &nbsp; at java.util.LinkedList.remove(LinkedList.java:788)<br>
          &nbsp; &nbsp; &nbsp; &nbsp; at
          java.util.LinkedList.removeFirst(LinkedList.java:134)<br>
          &nbsp; &nbsp; &nbsp; &nbsp; at
org.drools.common.PropagationContextImpl.evaluateActionQueue(PropagationContextImpl.java:344)<br>
          &nbsp; &nbsp; &nbsp; &nbsp; at
          org.drools.common.NamedEntryPoint.insert(NamedEntryPoint.java:342)<br>
          &nbsp; &nbsp; &nbsp; &nbsp; at
          org.drools.common.NamedEntryPoint.insert(NamedEntryPoint.java:298)<br>
          &nbsp; &nbsp; &nbsp; &nbsp; at
          org.drools.common.NamedEntryPoint.insert(NamedEntryPoint.java:123)<br>
          &nbsp; &nbsp; &nbsp; &nbsp; at
          org.drools.common.NamedEntryPoint.insert(NamedEntryPoint.java:53)<br>
          &nbsp; &nbsp; &nbsp; &nbsp; at overrun.Main.main(Main.java:64)<br>
          <br>
          5.3.0 is the last version without this bug.<br>
          <br>
          -W<br>
          <br>
          <br>
          On 14/05/2013, jpbarto &lt;<a moz-do-not-send="true"
            href="mailto:Jason.P.Barto@gmail.com">Jason.P.Barto@gmail.com</a>&gt;
          wrote:<br>
          &gt; First the specifics: JDK 1.6, Mac OSX, using Drools 5.5
          Final<br>
          &gt;<br>
          &gt; The full source code and rules are pasted below but
          here's the gist, I have<br>
          &gt; a stateful knowledge session to which I am inserting
          events and running an<br>
          &gt; accumulate on the input events. &nbsp;I have a for loop
          generating the events<br>
          &gt; and<br>
          &gt; inserting them as rapidly as possible. &nbsp;In the rules I
          use an accumulator<br>
          &gt; to<br>
          &gt; calculate the average of the values contained within the
          events. &nbsp;The<br>
          &gt; behavior I'm observing is that if I insert ~120 events
          without any waiting<br>
          &gt; I<br>
          &gt; receive an NPE. &nbsp;If I Thread.sleep for even just 1ms the
          test goes off<br>
          &gt; without a hitch. &nbsp;Have I uncovered a bug which should be
          logged in JIRA? &nbsp;I<br>
          &gt; would check through JIRA to see if something similar has
          been logged but<br>
          &gt; I'm<br>
          &gt; so unfamiliar with the codebase, not to mention it could
          all just be user<br>
          &gt; error.<br>
          &gt;<br>
          &gt; The NPE is as follows:<br>
          &gt; Exception in thread "main" java.lang.NullPointerException<br>
          &gt; &nbsp; &nbsp; &nbsp; at<br>
          &gt;
          org.drools.reteoo.AccumulateNode.getFirstMatch(AccumulateNode.java:1050)<br>
          &gt; &nbsp; &nbsp; &nbsp; at<br>
          &gt;
org.drools.reteoo.AccumulateNode.modifyLeftTuple(AccumulateNode.java:345)<br>
          &gt; &nbsp; &nbsp; &nbsp; at<br>
          &gt;
org.drools.reteoo.SingleLeftTupleSinkAdapter.propagateModifyChildLeftTuple(SingleLeftTupleSinkAdapter.java:259)<br>
          &gt; &nbsp; &nbsp; &nbsp; at<br>
          &gt;
org.drools.reteoo.AccumulateNode.evaluateResultConstraints(AccumulateNode.java:676)<br>
          &gt; &nbsp; &nbsp; &nbsp; at<br>
          &gt;
org.drools.reteoo.ReteooWorkingMemory$EvaluateResultConstraints.execute(ReteooWorkingMemory.java:590)<br>
          &gt; &nbsp; &nbsp; &nbsp; at<br>
          &gt;
org.drools.common.PropagationContextImpl.evaluateActionQueue(PropagationContextImpl.java:350)<br>
          &gt; &nbsp; &nbsp; &nbsp; at<br>
          &gt;
org.drools.rule.SlidingLengthWindow.assertFact(SlidingLengthWindow.java:119)<br>
          &gt; &nbsp; &nbsp; &nbsp; at
          org.drools.rule.BehaviorManager.assertFact(BehaviorManager.java:94)<br>
          &gt; &nbsp; &nbsp; &nbsp; at
          org.drools.reteoo.WindowNode.assertObject(WindowNode.java:167)<br>
          &gt; &nbsp; &nbsp; &nbsp; at<br>
          &gt;
org.drools.reteoo.CompositeObjectSinkAdapter.doPropagateAssertObject(CompositeObjectSinkAdapter.java:497)<br>
          &gt; &nbsp; &nbsp; &nbsp; at<br>
          &gt;
org.drools.reteoo.CompositeObjectSinkAdapter.propagateAssertObject(CompositeObjectSinkAdapter.java:382)<br>
          &gt; &nbsp; &nbsp; &nbsp; at
          org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:235)<br>
          &gt; &nbsp; &nbsp; &nbsp; at
          org.drools.reteoo.EntryPointNode.assertObject(EntryPointNode.java:240)<br>
          &gt; &nbsp; &nbsp; &nbsp; at
          org.drools.common.NamedEntryPoint.insert(NamedEntryPoint.java:350)<br>
          &gt; &nbsp; &nbsp; &nbsp; at
          org.drools.common.NamedEntryPoint.insert(NamedEntryPoint.java:311)<br>
          &gt; &nbsp; &nbsp; &nbsp; at
          org.drools.common.NamedEntryPoint.insert(NamedEntryPoint.java:127)<br>
          &gt; &nbsp; &nbsp; &nbsp; at
          org.drools.common.NamedEntryPoint.insert(NamedEntryPoint.java:55)<br>
          &gt; &nbsp; &nbsp; &nbsp; at drools5fusioneval.Average.main(Average.java:66)<br>
          &gt;<br>
          &gt; ### Average.java ###<br>
          &gt; package drools5fusioneval;<br>
          &gt;<br>
          &gt; import java.io.IOException;<br>
          &gt; import java.util.Random;<br>
          &gt; import org.drools.KnowledgeBase;<br>
          &gt; import org.drools.KnowledgeBaseConfiguration;<br>
          &gt; import org.drools.KnowledgeBaseFactory;<br>
          &gt; import org.drools.builder.KnowledgeBuilder;<br>
          &gt; import org.drools.builder.KnowledgeBuilderFactory;<br>
          &gt; import org.drools.builder.ResourceType;<br>
          &gt; import org.drools.conf.EventProcessingOption;<br>
          &gt; import org.drools.io.ResourceFactory;<br>
          &gt; import org.drools.runtime.StatefulKnowledgeSession;<br>
          &gt; import org.drools.runtime.rule.WorkingMemoryEntryPoint;<br>
          &gt;<br>
          &gt; class AvgDFEChannel implements org.drools.runtime.Channel
          {<br>
          &gt; &nbsp; &nbsp; @Override<br>
          &gt; &nbsp; &nbsp; public void send(Object o) {<br>
          &gt; &nbsp; &nbsp; &nbsp; &nbsp; System.err.println ("Recieved channel message: "+
          o);<br>
          &gt; &nbsp; &nbsp; }<br>
          &gt; }<br>
          &gt;<br>
          &gt; public class Average {<br>
          &gt; &nbsp; &nbsp; public static void main(String[] args) throws
          InterruptedException,<br>
          &gt; IOException {<br>
          &gt; &nbsp; &nbsp; &nbsp; &nbsp; KnowledgeBaseConfiguration kbconfig =<br>
          &gt; KnowledgeBaseFactory.newKnowledgeBaseConfiguration();<br>
          &gt; &nbsp; &nbsp; &nbsp; &nbsp; kbconfig.setOption(EventProcessingOption.STREAM);<br>
          &gt;<br>
          &gt; &nbsp; &nbsp; &nbsp; &nbsp; KnowledgeBase kbase =<br>
          &gt; KnowledgeBaseFactory.newKnowledgeBase(kbconfig);<br>
          &gt;<br>
          &gt; &nbsp; &nbsp; &nbsp; &nbsp; KnowledgeBuilder kbuilder =<br>
          &gt; KnowledgeBuilderFactory.newKnowledgeBuilder();<br>
          &gt;<br>
          &gt;
kbuilder.add(ResourceFactory.newClassPathResource("drools5fusioneval/average.drl"),<br>
          &gt; ResourceType.DRL);<br>
          &gt; &nbsp; &nbsp; &nbsp; &nbsp; if (kbuilder.hasErrors()) {<br>
          &gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
          System.err.println(kbuilder.getErrors().toString());<br>
          &gt; &nbsp; &nbsp; &nbsp; &nbsp; }<br>
          &gt; &nbsp; &nbsp; &nbsp; &nbsp;
          kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());<br>
          &gt;<br>
          &gt; &nbsp; &nbsp; &nbsp; &nbsp; final StatefulKnowledgeSession session =<br>
          &gt; kbase.newStatefulKnowledgeSession();<br>
          &gt; &nbsp; &nbsp; &nbsp; &nbsp; session.registerChannel("heartbeat", new
          AvgDFEChannel ());<br>
          &gt; &nbsp; &nbsp; &nbsp; &nbsp; WorkingMemoryEntryPoint ep01 =<br>
          &gt; session.getWorkingMemoryEntryPoint("ep01");<br>
          &gt;<br>
          &gt; &nbsp; &nbsp; &nbsp; &nbsp; new Thread() {<br>
          &gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public void run() {<br>
          &gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; session.fireUntilHalt();<br>
          &gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>
          &gt; &nbsp; &nbsp; &nbsp; &nbsp; }.start();<br>
          &gt;<br>
          &gt; &nbsp; &nbsp; &nbsp; &nbsp; Thread.sleep (5000); // give the engine time to
          get setup<br>
          &gt;<br>
          &gt; &nbsp; &nbsp; &nbsp; &nbsp; Server hiwaesdk = new Server ("hiwaesdk");<br>
          &gt; &nbsp; &nbsp; &nbsp; &nbsp; session.insert(hiwaesdk);<br>
          &gt; &nbsp; &nbsp; &nbsp; &nbsp; long LIMIT = 120;<br>
          &gt; &nbsp; &nbsp; &nbsp; &nbsp; Random rnd = new Random (System.nanoTime());<br>
          &gt;<br>
          &gt; &nbsp; &nbsp; &nbsp; &nbsp; for (long i = LIMIT; i &gt; 0; i--) {<br>
          &gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int j = rnd.nextInt (212);<br>
          &gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ep01.insert (new IntEvent (j));<br>
          &gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Thread.sleep (0x1);<br>
          &gt; &nbsp; &nbsp; &nbsp; &nbsp; }<br>
          &gt;<br>
          &gt; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println (hiwaesdk);<br>
          &gt; &nbsp; &nbsp; }<br>
          &gt; }<br>
          &gt;<br>
          &gt;<br>
          &gt; ### average.drl ###<br>
          &gt; package drools5fusioneval<br>
          &gt;<br>
          &gt; declare IntEvent<br>
          &gt; &nbsp; &nbsp; @role ( event )<br>
          &gt; &nbsp; &nbsp; @expires(15s)<br>
          &gt; end<br>
          &gt;<br>
          &gt; declare Statistics<br>
          &gt; &nbsp; &nbsp; opsec : long<br>
          &gt; &nbsp; &nbsp; total : long<br>
          &gt; end<br>
          &gt; global Statistics stats;<br>
          &gt;<br>
          &gt; rule "Init engine"<br>
          &gt; &nbsp; &nbsp; salience 100<br>
          &gt; when<br>
          &gt; then<br>
          &gt; &nbsp; &nbsp; stats = new Statistics ();<br>
          &gt; &nbsp; &nbsp; stats.setTotal (0);<br>
          &gt; &nbsp; &nbsp; stats.setOpsec (0);<br>
          &gt; &nbsp; &nbsp; drools.getWorkingMemory ().setGlobal ("stats",
          stats);<br>
          &gt; &nbsp; &nbsp; System.out.println ("Engine initialized");<br>
          &gt; end<br>
          &gt;<br>
          &gt; rule "number rule"<br>
          &gt; when<br>
          &gt; &nbsp; &nbsp; $e : IntEvent () from entry-point ep01<br>
          &gt; &nbsp; &nbsp; $s : Server (hostname == "hiwaesdk")<br>
          &gt; then<br>
          &gt; &nbsp; &nbsp; $s.currentTemp = $e.data;<br>
          &gt; &nbsp; &nbsp; stats.setOpsec (stats.getOpsec () + 1);<br>
          &gt; &nbsp; &nbsp; stats.setTotal (stats.getTotal () + 1);<br>
          &gt; end<br>
          &gt;<br>
          &gt; rule "average temp"<br>
          &gt; when<br>
          &gt; &nbsp; &nbsp; Number ($avg : intValue) from accumulate (<br>
          &gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IntEvent ($temp : data) over
          window:length(10) from entry-point<br>
          &gt; ep01, average ($temp)<br>
          &gt; &nbsp; &nbsp; &nbsp; &nbsp; )<br>
          &gt; &nbsp; &nbsp; $s : Server (hostname == "hiwaesdk")<br>
          &gt; then<br>
          &gt; &nbsp; &nbsp; $s.avgTemp = $avg;<br>
          &gt; end<br>
          &gt;<br>
          &gt; rule "Heartbeat"<br>
          &gt; &nbsp; &nbsp; timer ( int: 5s 5s)<br>
          &gt; when<br>
          &gt; then<br>
          &gt; &nbsp; &nbsp; channels["heartbeat"].send ("Heartbeat: "+
          stats.getOpsec () / 5 +", "+<br>
          &gt; stats.getTotal ());<br>
          &gt; &nbsp; &nbsp; stats.setOpsec (0);<br>
          &gt; end<br>
          &gt;<br>
          &gt;<br>
          &gt;<br>
          &gt; --<br>
          &gt; View this message in context:<br>
          &gt; <a moz-do-not-send="true"
href="http://drools.46999.n3.nabble.com/NPE-from-reteoo-AccumulateNode-tp4023810.html"
            target="_blank">http://drools.46999.n3.nabble.com/NPE-from-reteoo-AccumulateNode-tp4023810.html</a><br>
          &gt; Sent from the Drools: User forum mailing list archive at
          Nabble.com.<br>
          &gt; _______________________________________________<br>
          &gt; rules-users mailing list<br>
          &gt; <a moz-do-not-send="true"
            href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
          &gt; <a moz-do-not-send="true"
            href="https://lists.jboss.org/mailman/listinfo/rules-users"
            target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
          &gt;<br>
          _______________________________________________<br>
          rules-users mailing list<br>
          <a moz-do-not-send="true"
            href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
          <a moz-do-not-send="true"
            href="https://lists.jboss.org/mailman/listinfo/rules-users"
            target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
        </blockquote>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
rules-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a>
<a class="moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a></pre>
    </blockquote>
    <br>
  </body>
</html>