I am no expert on drools; however, you might want to retract loanDeduction from the Working Memory if it is null. Your first rule determines that it is null and then you set the value (ld = 0f); however, you should be using an insert to put this into working memory. The other alternative is to retract the loan Deduction from working memory and add a logic check in the Nett Salary rule to see if loan Dedcution is null.
I am working on some Drools stuff today if you need some more help on this.
Shannon
I am facing problems which many have encountered in the past. I searched
forums but could not get precise answer. The problem is with null values in
Wrapper objects. See the following code:
rule "Null Check " salience 100
when
Salary ( ld : loanDeduction==null || < 0f ) // loanDeduction
is java.lang.Float
then
log("Load return is null"); //Global function
ld = 0f;
end
rule "Nett Salary" salience 70
when
Salary ( nett != ( gross – loanDeduction – pf) )
then
log("Invalid nett salary amount");
end
You may have idea what I am trying to do. But I get NullPointerException in
“Nett Salary” rule when I fire the rules having fact with null in the
loanDeduction attribute. I believe my “Null Check” exception should execute
first and it does when I put negative value in loadDeduction. What is
solution in such a case?
--
View this message in context: http://www.nabble.com/NullPointerException-with-Wrapper-objects-tp23515500p23515500.html
Sent from the drools - user mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users