[rules-users] Rules called with null references?

Wolfgang Laun wolfgang.laun at gmail.com
Fri Nov 18 01:38:38 EST 2011


The NPE could be triggered by the update call, happens in another rule's
LHS.

It's possible that the fact reference bound to $secondAlert is already gone
by the time that NPE happens - I'm not sure about that.

-W

On 17 November 2011 23:03, Robert Crawford <crawford at kloognome.com> wrote:

> I enhanced my ConsequenceExceptionHandler and have a little more detail on
> this. I have this rule:
>
> rule "Duplicate Alerts"
> when
>    $firstAlert : TemperatureAlert( this.saved, this.valid )
>    $secondAlert : TemperatureAlert (this.location == $firstAlert.location,
> this != $firstAlert, this.saved, this.valid )
> then
>    LOG.info("Removing duplicate alert for " + $firstAlert.getLocation());
>    $secondAlert.setValid(false);
>    $secondAlert.setInvalidAt(new Date());
>    update($secondAlert);
> end
>
> The TemperatureAlert class is not defined as an event.
>
> I'm getting this exception:
>
> 15:56:34,145 ERROR [STDERR] CONSEQUENCE EXCEPTION
> 15:56:34,145 ERROR [STDERR] Exception executing consequence for rule
> "Duplicate Alerts" in xxx.xxxxxxx.rules: java.lang.NullPointerException
> 15:56:34,145 ERROR [STDERR] START FACT DUMP:
> 15:56:34,145 ERROR [STDERR]
> $firstAlert:xxx.xxxxxxx.TemperatureAlert at 1e3c1689
> 15:56:34,145 ERROR [STDERR] $secondAlert:null
> 15:56:34,145 ERROR [STDERR] END FACT DUMP
> 15:56:34,145 ERROR [STDERR] Exception executing consequence for rule
> "Duplicate Alerts" in xxx.xxxxxxx.rules: java.lang.NullPointerException
>
>
> I don't see how this activation could have ever happened.
>
> If there never was an object that qualified, the activation would never
> have
> been scheduled.
>
> If there was one, but it was updated so it no longer matched or was
> retracted, then the activation would have been cancelled.
>
> Everything -- EVERYTHING -- for the session is done within a single thread:
>
>           Runnable r = new Runnable() {
>                public void run() {
>                    while (!shuttingDown) {
>                        try {
>                            session.fireUntilHalt();
>                            while (!commandList.isEmpty()) {
>                                commandList.take().execute();
>                            }
>                        } catch (Throwable t) {
>                            t.printStackTrace();
>                        }
>                    }
>                }
>            };
>
> The "commandList" is a BlockingQueue of objects that, when execute() is
> called, variously insert, retract, or update objects. All the data feeding
> into the session flows through that queue. The halt() method is called
> either when the queue gets too long and periodically if it's not empty.
>
> Any ideas?
>
> --
> View this message in context:
> http://drools.46999.n3.nabble.com/Rules-called-with-null-references-tp3477164p3517204.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20111118/85136fcf/attachment.html 


More information about the rules-users mailing list