user991255
user991255

Reputation: 355

Exception executing consequence for rule (Drools, Guvnor, JBPM5)

am new to BPM, using JBPM5.4 installer.

below is the my drl source code taken from Guvnor.. when firing the rules am getting the error.

rule "TestRule"
        dialect "java"
        when
            exists (Person( name == "estaban" ))
        then
            Person.setName( "ESTABAN" );
    end

StackTrace:

Exception in thread "main" Exception executing consequence for rule "TestRule" in com.tcs: java.lang.NullPointerExceptio
n
    at org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.j
ava:39)
    at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1297)
    at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:1221)
    at org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1456)
    at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:710)
    at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:674)
    at org.drools.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:230)
    at com.sample.ProcessMain.main(ProcessMain.java:41)
Caused by: java.lang.NullPointerException
    at com.tcs.Rule_TestRule_063717b0a0b841d3ae5b0d9fa14879f8.defaultConsequence(Rule_TestRule_063717b0a0b841d3ae5b0d9fa148
79f8.java:7)
    at com.tcs.Rule_TestRule_063717b0a0b841d3ae5b0d9fa14879f8DefaultConsequenceInvokerGenerated.evaluate(Unknown Source)
    at com.tcs.Rule_TestRule_063717b0a0b841d3ae5b0d9fa14879f8DefaultConsequenceInvoker.evaluate(Unknown Source)
    at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1287)
    ... 6 more

Upvotes: 1

Views: 6407

Answers (1)

Steve
Steve

Reputation: 9480

You need to bind the fact found in the left-hand-side to a variable. Re-write like so:

rule "TestRule"
    dialect "java"
when
    $person: Person( name == "estaban" )
then
    $person.setName( "ESTABAN" );
    update( $person );
end

To do this in Guvnor, when you add/modify the constraint, you will see a "Modify constraints for Person" dialog box. You need to type a variable name such as "$person" in the "Variable name" text box.

This will cause it to change the generated DRL from :

Person( name == "estaban" )

to:

$person: Person( name == "estaban" )

Once you have bound the variable on the LHS then you need to modify the RHS. Select the option "Modify a field of an existing fact". You then need to select your variable name from the list provided and provide the details of which property to modify.

Upvotes: 2

Related Questions