Note: This is a beta release of Red Hat Bugzilla 5.0. The data contained within is a snapshot of the live data so any changes you make will not be reflected in the production Bugzilla. Also email is disabled so feel free to test any aspect of the site that you want. File any problems you find or give feedback here.

Bug 1059372

Summary: NPE in a timer node when a left tuple get activated immediately and then rescheduled in the same node evaluation
Product: [Retired] JBoss BRMS Platform 6 Reporter: Mario Fusco <mfusco>
Component: BREAssignee: Mario Fusco <mfusco>
Status: CLOSED CURRENTRELEASE QA Contact: Marek Winkler <mwinkler>
Severity: urgent Docs Contact:
Priority: urgent    
Version: 6.0.0CC: etirelli, kverlaen, lpetrovi
Target Milestone: ER1   
Target Release: 6.0.1   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2014-08-06 19:58:23 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Description Mario Fusco 2014-01-29 18:00:57 UTC
When a left tuple get activated immediately and then rescheduled in the same evaluation loop fo a timer node the following Exception is thrown:

java.lang.NullPointerException
	at org.drools.core.phreak.PhreakTimerNode.doPropagateChildLeftTuple(PhreakTimerNode.java:358)
	at org.drools.core.phreak.PhreakTimerNode.doPropagateChildLeftTuples(PhreakTimerNode.java:326)
	at org.drools.core.phreak.PhreakTimerNode.doNode(PhreakTimerNode.java:72)
	at org.drools.core.phreak.RuleNetworkEvaluator.innerEval(RuleNetworkEvaluator.java:357)
	at org.drools.core.phreak.RuleNetworkEvaluator.outerEval(RuleNetworkEvaluator.java:161)
	at org.drools.core.phreak.RuleNetworkEvaluator.evaluateNetwork(RuleNetworkEvaluator.java:116)
	at org.drools.core.phreak.RuleExecutor.reEvaluateNetwork(RuleExecutor.java:200)
	at org.drools.core.phreak.RuleExecutor.evaluateNetworkAndFire(RuleExecutor.java:67)
	at org.drools.core.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:935)
	at org.drools.core.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1200)
	at org.drools.core.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:958)
	at org.drools.core.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:932)
	at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:232)
	at org.drools.compiler.integrationtests.Misc2Test.testCronFire(Misc2Test.java:5192)

The following test case reproduces the problem:

    @Test
    public void testCronFire() throws InterruptedException {
        String drl = "package test.drools\n" +
                     "rule TestRule " +
                     "  timer (cron:* * * * * ?) " +
                     "when\n" +
                     "    String() " +
                     "    Integer() " +
                     "then\n" +
                     "end\n";

        KnowledgeBase kbase = loadKnowledgeBaseFromString(drl);
        StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();

        int repetitions = 10000;
        for (int j = 0; j < repetitions; j++ ) {
            ksession.insert( j );
        }

        ksession.insert( "go" );
        ksession.fireAllRules();
    }

Comment 2 Mario Fusco 2014-01-29 18:46:20 UTC
Fixed by https://github.com/droolsjbpm/drools/commit/5af33eba2

Comment 3 Marek Winkler 2014-02-21 16:47:31 UTC
Verified that the fix is present in BRMS 6.0.1 ER1 and the corresponding test passes.