[rules-users] Defeasible: NPE: with multiple @Defeasible

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

[rules-users] Defeasible: NPE: with multiple @Defeasible

Borris
Hi Davide,

I've got a null pointer exception with defeasible. My test case is:

package com.sample

declare Fact
     fact: String @key
end

rule init
     when
     then
         System.out.println("inserting initial facts");
         insert( new Fact( "one" ) );
         insert( new Fact( "two" ) );
         insert( new Fact( "two" ) );
end

rule rule1
     @Defeasible
     enabled true
     when
         Fact( "one"; )
     then
         System.out.println("one causes wibble");
         insertLogical( new Fact( "wibble") );
end

rule rule2
     @Defeasible
     when
         Fact( "two"; )
     then
         System.out.println("two causes wibble");
         insertLogical( new Fact( "wibble") );
end

rule rule3
     @Defeater
     @Defeats( "rule2" )
     when
         Fact( "two"; )
     then
         System.out.println("two negates wibble");
         insertLogical( new Fact( "wibble"), "neg" );
end

The output I get is

inserting initial facts
one causes wibble
two causes wibble
two causes wibble
two negates wibble
two negates wibble
Exception executing consequence for rule "rule3" in com.sample:
java.lang.NullPointerException
     at
org.drools.core.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39)
     at
org.drools.core.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1057)
     at org.drools.core.phreak.RuleExecutor.fire(RuleExecutor.java:152)
     at
org.drools.core.phreak.RuleExecutor.evaluateNetworkAndFire(RuleExecutor.java:94)
     at
org.drools.core.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:964)
     at
org.drools.core.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1234)
     at
org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1239)
     at
org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1212)
     at com.sample.DroolsTest.main(DroolsTest.java:21)
Caused by: java.lang.NullPointerException
     at
org.drools.core.beliefsystem.defeasible.DefeasibleBeliefSet.removeUndefeated(DefeasibleBeliefSet.java:295)
     at
org.drools.core.beliefsystem.defeasible.DefeasibleBeliefSet.add(DefeasibleBeliefSet.java:126)
     at
org.drools.core.beliefsystem.jtms.JTMSBeliefSystem.insert(JTMSBeliefSystem.java:52)
     at
org.drools.core.beliefsystem.defeasible.DefeasibleBeliefSystem.insert(DefeasibleBeliefSystem.java:45)
     at
org.drools.core.common.TruthMaintenanceSystem.addLogicalDependency(TruthMaintenanceSystem.java:136)
     at
org.drools.core.common.TruthMaintenanceSystem.addLogicalDependency(TruthMaintenanceSystem.java:107)
     at
org.drools.core.common.NamedEntryPoint.insert(NamedEntryPoint.java:234)
     at
org.drools.core.impl.StatefulKnowledgeSessionImpl.insert(StatefulKnowledgeSessionImpl.java:1430)
     at
org.drools.core.base.DefaultKnowledgeHelper.insertLogical(DefaultKnowledgeHelper.java:275)
     at
org.drools.core.base.DefaultKnowledgeHelper.insertLogical(DefaultKnowledgeHelper.java:247)
     at
com.sample.Rule_rule32132126114.defaultConsequence(Rule_rule32132126114.java:8)
     at
com.sample.Rule_rule32132126114DefaultConsequenceInvokerGenerated.evaluate(Unknown
Source)
     at
com.sample.Rule_rule32132126114DefaultConsequenceInvoker.evaluate(Unknown Source)
     at
org.drools.core.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1046)
     ... 7 more


I believe I am using snapshot 6.1.0.201407170510 but I suspect the
precise version doesn't matter too much.

In the above example, if you disable rule1 then the NPE doesn't happen.
Only doing one "two" fact insertion in the init rule likewise means the
NPE doesn't happen. I think the issue is something like rule3 does more
than one defeat on rule2's scoring on "wibble" fact, but rule1 still has
a say in the continuing existence of the "wibble" fact.

Should I get a Jira log in and enter these well qualified bugs directly?

Regards,

Borris





_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] Defeasible: NPE: with multiple @Defeasible

Mark Proctor
Stack trace shows the error:
org.drools.core.beliefsystem.defeasible.DefeasibleBeliefSet.removeUndefeated(DefeasibleBeliefSet.java:295)
https://github.com/sotty/drools/blob/master/drools-core/src/main/java/org/drools/core/beliefsystem/defeasible/DefeasibleBeliefSet.java

Maybe have a go fixing it yourself? And submit the fix with a unit test, as a pull request?
http://docs.jboss.org/drools/release/5.6.0.Final/droolsjbpm-introduction-docs/html/gettingstarted.html

Mark
On 22 Jul 2014, at 20:40, Borris <[hidden email]> wrote:

> Hi Davide,
>
> I've got a null pointer exception with defeasible. My test case is:
>
> package com.sample
>
> declare Fact
>     fact: String @key
> end
>
> rule init
>     when
>     then
>         System.out.println("inserting initial facts");
>         insert( new Fact( "one" ) );
>         insert( new Fact( "two" ) );
>         insert( new Fact( "two" ) );
> end
>
> rule rule1
>     @Defeasible
>     enabled true
>     when
>         Fact( "one"; )
>     then
>         System.out.println("one causes wibble");
>         insertLogical( new Fact( "wibble") );
> end
>
> rule rule2
>     @Defeasible
>     when
>         Fact( "two"; )
>     then
>         System.out.println("two causes wibble");
>         insertLogical( new Fact( "wibble") );
> end
>
> rule rule3
>     @Defeater
>     @Defeats( "rule2" )
>     when
>         Fact( "two"; )
>     then
>         System.out.println("two negates wibble");
>         insertLogical( new Fact( "wibble"), "neg" );
> end
>
> The output I get is
>
> inserting initial facts
> one causes wibble
> two causes wibble
> two causes wibble
> two negates wibble
> two negates wibble
> Exception executing consequence for rule "rule3" in com.sample:
> java.lang.NullPointerException
>     at
> org.drools.core.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39)
>     at
> org.drools.core.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1057)
>     at org.drools.core.phreak.RuleExecutor.fire(RuleExecutor.java:152)
>     at
> org.drools.core.phreak.RuleExecutor.evaluateNetworkAndFire(RuleExecutor.java:94)
>     at
> org.drools.core.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:964)
>     at
> org.drools.core.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1234)
>     at
> org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1239)
>     at
> org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1212)
>     at com.sample.DroolsTest.main(DroolsTest.java:21)
> Caused by: java.lang.NullPointerException
>     at
> org.drools.core.beliefsystem.defeasible.DefeasibleBeliefSet.removeUndefeated(DefeasibleBeliefSet.java:295)
>     at
> org.drools.core.beliefsystem.defeasible.DefeasibleBeliefSet.add(DefeasibleBeliefSet.java:126)
>     at
> org.drools.core.beliefsystem.jtms.JTMSBeliefSystem.insert(JTMSBeliefSystem.java:52)
>     at
> org.drools.core.beliefsystem.defeasible.DefeasibleBeliefSystem.insert(DefeasibleBeliefSystem.java:45)
>     at
> org.drools.core.common.TruthMaintenanceSystem.addLogicalDependency(TruthMaintenanceSystem.java:136)
>     at
> org.drools.core.common.TruthMaintenanceSystem.addLogicalDependency(TruthMaintenanceSystem.java:107)
>     at
> org.drools.core.common.NamedEntryPoint.insert(NamedEntryPoint.java:234)
>     at
> org.drools.core.impl.StatefulKnowledgeSessionImpl.insert(StatefulKnowledgeSessionImpl.java:1430)
>     at
> org.drools.core.base.DefaultKnowledgeHelper.insertLogical(DefaultKnowledgeHelper.java:275)
>     at
> org.drools.core.base.DefaultKnowledgeHelper.insertLogical(DefaultKnowledgeHelper.java:247)
>     at
> com.sample.Rule_rule32132126114.defaultConsequence(Rule_rule32132126114.java:8)
>     at
> com.sample.Rule_rule32132126114DefaultConsequenceInvokerGenerated.evaluate(Unknown
> Source)
>     at
> com.sample.Rule_rule32132126114DefaultConsequenceInvoker.evaluate(Unknown Source)
>     at
> org.drools.core.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1046)
>     ... 7 more
>
>
> I believe I am using snapshot 6.1.0.201407170510 but I suspect the
> precise version doesn't matter too much.
>
> In the above example, if you disable rule1 then the NPE doesn't happen.
> Only doing one "two" fact insertion in the init rule likewise means the
> NPE doesn't happen. I think the issue is something like rule3 does more
> than one defeat on rule2's scoring on "wibble" fact, but rule1 still has
> a say in the continuing existence of the "wibble" fact.
>
> Should I get a Jira log in and enter these well qualified bugs directly?
>
> Regards,
>
> Borris
>
>
>
>
>
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users


_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] Defeasible: NPE: with multiple @Defeasible

Borris

On 22/07/2014 22:44, Mark Proctor wrote:
> Stack trace shows the error:
> org.drools.core.beliefsystem.defeasible.DefeasibleBeliefSet.removeUndefeated(DefeasibleBeliefSet.java:295)
> https://github.com/sotty/drools/blob/master/drools-core/src/main/java/org/drools/core/beliefsystem/defeasible/DefeasibleBeliefSet.java
>
> Maybe have a go fixing it yourself? And submit the fix with a unit test, as a pull request?
> http://docs.jboss.org/drools/release/5.6.0.Final/droolsjbpm-introduction-docs/html/gettingstarted.html
>

I might well have a go, but there's a whole bunch of learning I need to
do before I can submit my first candidate patch. So don't expect
something too quickly.

Borris

_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] Defeasible: NPE: with multiple @Defeasible

Mark Proctor

On 23 Jul 2014, at 21:58, Borris <[hidden email]> wrote:

>
> On 22/07/2014 22:44, Mark Proctor wrote:
>> Stack trace shows the error:
>> org.drools.core.beliefsystem.defeasible.DefeasibleBeliefSet.removeUndefeated(DefeasibleBeliefSet.java:295)
>> https://github.com/sotty/drools/blob/master/drools-core/src/main/java/org/drools/core/beliefsystem/defeasible/DefeasibleBeliefSet.java
>>
>> Maybe have a go fixing it yourself? And submit the fix with a unit test, as a pull request?
>> http://docs.jboss.org/drools/release/5.6.0.Final/droolsjbpm-introduction-docs/html/gettingstarted.html
>>
>
> I might well have a go, but there's a whole bunch of learning I need to
> do before I can submit my first candidate patch. So don't expect
> something too quickly.
We are available for real time chat on irc, if you need help.
http://drools.jboss.org/irc

Either way best way to start is to submit a compact self contained unit test, to show the failure, as a pull request. Don’t forget to @Ignore it, so it won’t break our build and we can fix it later:
https://github.com/droolsjbpm/drools/blob/master/drools-compiler/src/test/java/org/drools/compiler/beliefsystem/defeasible/DefeasibilityTest.java

Mark
>
> Borris
>
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users


_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] Defeasible: NPE: with multiple @Defeasible

Davide Sottara
In reply to this post by Borris
Fixed, in PR status. It was indeed another bug.
https://github.com/sotty/drools/commit/7941a0c8d7e66c6c7719c14ca58d798337d067d8

Thanks for reporting, we really appreciate the feedback
Davide

On 07/23/2014 10:58 PM, Borris wrote:

> On 22/07/2014 22:44, Mark Proctor wrote:
>> Stack trace shows the error:
>> org.drools.core.beliefsystem.defeasible.DefeasibleBeliefSet.removeUndefeated(DefeasibleBeliefSet.java:295)
>> https://github.com/sotty/drools/blob/master/drools-core/src/main/java/org/drools/core/beliefsystem/defeasible/DefeasibleBeliefSet.java
>>
>> Maybe have a go fixing it yourself? And submit the fix with a unit test, as a pull request?
>> http://docs.jboss.org/drools/release/5.6.0.Final/droolsjbpm-introduction-docs/html/gettingstarted.html
>>
> I might well have a go, but there's a whole bunch of learning I need to
> do before I can submit my first candidate patch. So don't expect
> something too quickly.
>
> Borris
>
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users
>

_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] Defeasible: NPE: with multiple @Defeasible

Borris
Wow, excellent Davide. I've been travelling and will give a go over the
next day (or so). Non-trivial @defeasible and constants in queries
really open up lots of things I've been wanting to try!

Regards

Borris

On Saturday 26/07/2014 00:39, Davide Sottara wrote:

> Fixed, in PR status. It was indeed another bug.
> https://github.com/sotty/drools/commit/7941a0c8d7e66c6c7719c14ca58d798337d067d8
>
> Thanks for reporting, we really appreciate the feedback
> Davide
>
> On 07/23/2014 10:58 PM, Borris wrote:
>> On 22/07/2014 22:44, Mark Proctor wrote:
>>> Stack trace shows the error:
>>> org.drools.core.beliefsystem.defeasible.DefeasibleBeliefSet.removeUndefeated(DefeasibleBeliefSet.java:295)
>>> https://github.com/sotty/drools/blob/master/drools-core/src/main/java/org/drools/core/beliefsystem/defeasible/DefeasibleBeliefSet.java
>>>
>>> Maybe have a go fixing it yourself? And submit the fix with a unit test, as a pull request?
>>> http://docs.jboss.org/drools/release/5.6.0.Final/droolsjbpm-introduction-docs/html/gettingstarted.html
>>>
>> I might well have a go, but there's a whole bunch of learning I need to
>> do before I can submit my first candidate patch. So don't expect
>> something too quickly.
>>
>> Borris
>>
>> _______________________________________________
>> rules-users mailing list
>> [hidden email]
>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users

_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users