[rules-users] NullPointerException with Wrapper objects

Greg Barton greg_barton at yahoo.com
Wed May 13 02:15:54 EDT 2009


All conditions of all applicable rules are evaluated when you insert an object into working memory.  This decides which rule actions can go on the agenda.  Only when a rule action is on the agenda is the salience used to determine the order of action firing.  So doing the null check in the way you're doing it will not work.

You must put the null check in the same rule, before the potentially null property is used.

rule "Nett Salary" salience 70
  when
    Salary ( loanDeduction != null, nett != ( gross – loanDeduction – pf) )
  then
    log("Invalid nett salary amount");
end


--- On Wed, 5/13/09, dhai <sdhari at hotmail.com> wrote:

> From: dhai <sdhari at hotmail.com>
> Subject: [rules-users] NullPointerException with Wrapper objects
> To: rules-users at lists.jboss.org
> Date: Wednesday, May 13, 2009, 12:14 AM
> 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 at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users


      




More information about the rules-users mailing list