Bug 1106300
| Summary: | NPE at org.drools.core.util.index.LeftTupleIndexHashTable.remove for Stateful Knowledge Session | ||||||||
|---|---|---|---|---|---|---|---|---|---|
| Product: | [Retired] JBoss BRMS Platform 6 | Reporter: | Thiago Araki <taraki> | ||||||
| Component: | BRE | Assignee: | Mario Fusco <mfusco> | ||||||
| Status: | CLOSED CURRENTRELEASE | QA Contact: | Marek Winkler <mwinkler> | ||||||
| Severity: | high | Docs Contact: | |||||||
| Priority: | high | ||||||||
| Version: | 6.0.1 | CC: | etirelli, kverlaen, mfusco, rrajasek | ||||||
| Target Milestone: | CR1 | ||||||||
| Target Release: | 6.0.2 | ||||||||
| Hardware: | x86_64 | ||||||||
| OS: | Linux | ||||||||
| Whiteboard: | |||||||||
| Fixed In Version: | Doc Type: | Bug Fix | |||||||
| Doc Text: | Story Points: | --- | |||||||
| Clone Of: | Environment: | ||||||||
| Last Closed: | 2014-08-06 19:54:45 UTC | Type: | Bug | ||||||
| Regression: | --- | Mount Type: | --- | ||||||
| Documentation: | --- | CRM: | |||||||
| Verified Versions: | Category: | --- | |||||||
| oVirt Team: | --- | RHEL 7.3 requirements from Atomic Host: | |||||||
| Cloudforms Team: | --- | Target Upstream Version: | |||||||
| Embargoed: | |||||||||
| Attachments: |
|
||||||||
Thiago, I am investigating the issue you reported using your reproducer (thanks a lot for it). Indeed we have a bug there and I'll try to fix it asap. In the meanwhile if you need a workaround for it you can try to replace the eval ($cnt > 0) after the accumulates with a exists Reading( type == $type ) before it. Hello Mario, thanks for investigating it.
I tried the workaround you explained (see one of my rules below), but I had the same results.
Is there something else I should be doing?
rule "Abnormal"
dialect "mvel"
when
threshold : Threshold ($type : type, $limHL : limitHardLow, $limSL : limitSoftLow, $limHH : limitHardHigh, $limSH : limitSoftHigh)
exists Reading( type == $type ) from entry-point "entrypoint"
accumulate( reading : Reading( type == $type ) over window:length( 10 ) from entry-point "entrypoint", $avg : average( reading.value ), $cnt : count( 1 ) )
eval (($avg < $limSL && $avg >= $limHL) || ($avg > $limSH && $avg <= $limHH))
not Alarm (type == $type, endDate == null)
then
Alarm alarm = new Alarm();
alarm.setType($type);
alarm.setBeginDate(new java.util.Date());
alarm.setLevel( "ABNORMAL" );
insert(alarm);
System.out.println("CREATED ABNORMAL ALARM - VALUE = " + $avg);
end
Sorry Thiago, you're right. I am still investigating the problem and I believe the bug is somewhat related with evals. So, in addition to this, you should also eliminate the 2nd eval. For instance you could replace it with a pattern matching like it follows.
rule "Abnormal"
dialect "mvel"
when
threshold : Threshold ($type : type, $limHL : limitHardLow, $limSL : limitSoftLow, $limHH : limitHardHigh, $limSH : limitSoftHigh)
exists Reading( type == $type ) from entry-point "entrypoint"
Number( floatValue < $limSL && floatValue >= $limHL ) from accumulate( reading : Reading( type == $type ) over window:length( 10 ) from entry-point "entrypoint", average( reading.value ) )
not Alarm (type == $type, endDate == null)
then
Alarm alarm = new Alarm();
alarm.setType($type);
alarm.setBeginDate(new java.util.Date());
alarm.setLevel( "ABNORMAL" );
insert(alarm);
System.out.println("CREATED ABNORMAL ALARM - VALUE = " + $avg);
end
Let me know if this works for you.
Mario
Mario, I removed the "evals" from my rules, and changed them all to use the pattern matching as you instructed, but now I am receiving the following error after the second fact insertion: Exception in thread "Thread-0" java.lang.NullPointerException at org.drools.core.common.DoubleBetaConstraints.isAllowedCachedLeft(DoubleBetaConstraints.java:108) at org.drools.core.phreak.PhreakAccumulateNode.evaluateResultConstraints(PhreakAccumulateNode.java:710) at org.drools.core.phreak.PhreakAccumulateNode.doNode(PhreakAccumulateNode.java:89) at org.drools.core.phreak.RuleNetworkEvaluator.switchOnDoBetaNode(RuleNetworkEvaluator.java:562) at org.drools.core.phreak.RuleNetworkEvaluator.evalBetaNode(RuleNetworkEvaluator.java:533) at org.drools.core.phreak.RuleNetworkEvaluator.innerEval(RuleNetworkEvaluator.java:334) 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:194) 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.fireUntilHalt(DefaultAgenda.java:1160) at org.drools.core.common.AbstractWorkingMemory.fireUntilHalt(AbstractWorkingMemory.java:1002) at org.drools.core.common.AbstractWorkingMemory.fireUntilHalt(AbstractWorkingMemory.java:978) at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireUntilHalt(StatefulKnowledgeSessionImpl.java:273) at br.com.redhat.testcase.Runner$1.run(TestCase.java:30) Thiago, this seems to be a different issue and I cannot reproduce it. Can you please also attach your modified test case reproducing this problem? Thanks, Mario Cherry-picked to 6.1.x branch with https://github.com/droolsjbpm/drools/commit/f6af4dbc1 Created attachment 907611 [details]
Project with a new test case
Mario, I am attaching "test-case2" project that reproduces this different issue (NPE at org.drools.core.common.DoubleBetaConstraints.isAllowedCachedLeft).
If this is the case, I can open a new BZ, but please let me know.
Thanks,
Thiago
Cherry-picked to 6.0.x branch with https://github.com/droolsjbpm/drools/commit/0f990e02b Verified on BRMS 6.0.2 CR1. |
Created attachment 904461 [details] Project with a test case Description of problem: I am creating an application where there is a set of sensors sending feeds and rules which have to raise alerts with different levels based on average values. After some correct executions, this NPE is occuring. Version-Release number of selected component (if applicable): JBoss BRMS 6.0.1 GA How reproducible: Easy. Use the attached project (test-case.zip). Steps to Reproduce: 1. Create rules that receive events from an entry-point and calculate average values with Accumulate function in a window with length 10. 2. Create an Stateful Knowledge Session with Stream Mode and use the method fireUntilhalt() to execute rules. 3. Insert events in the entry point until the "Null Pointer Exception" occurs Actual results: Exception in thread "Thread-0" java.lang.NullPointerException at org.drools.core.util.index.LeftTupleIndexHashTable.remove(LeftTupleIndexHashTable.java:386) at org.drools.core.phreak.RuleNetworkEvaluator.doUpdatesReorderLeftMemory(RuleNetworkEvaluator.java:799) at org.drools.core.phreak.PhreakJoinNode.doNode(PhreakJoinNode.java:38) at org.drools.core.phreak.RuleNetworkEvaluator.switchOnDoBetaNode(RuleNetworkEvaluator.java:547) at org.drools.core.phreak.RuleNetworkEvaluator.evalBetaNode(RuleNetworkEvaluator.java:533) at org.drools.core.phreak.RuleNetworkEvaluator.innerEval(RuleNetworkEvaluator.java:334) 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:194) 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.fireUntilHalt(DefaultAgenda.java:1160) at org.drools.core.common.AbstractWorkingMemory.fireUntilHalt(AbstractWorkingMemory.java:1002) at org.drools.core.common.AbstractWorkingMemory.fireUntilHalt(AbstractWorkingMemory.java:978) at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireUntilHalt(StatefulKnowledgeSessionImpl.java:273) at br.com.redhat.testcase.Runner$1.run(TestCase.java:30) Expected results: Rules should fire correctly Additional info: I am attaching a maven project (test-case.zip) which has a test case for this scenario. You just need to import it, execute main class "TestCase" and check results on console. After the sixth event inserted, the NPE occurs.