NullPointerException in drools 5.5.0-final when retracting

I´ve got a problem with the following rule:

rule "Término sin Traducción"
    salience -100
    dialect "mvel"
    when
        traductor : TraductorDeEventosTratados()
            eventoGenerico : EventoGenerico() from traductor.eventoGenerico
    then
        System.out.println("Evento generico: " + eventoGenerico);
            traductor.setEventoGenerico( null );
            update( traductor );
            retract( eventoGenerico );
end

It causes a NullPointerException when retracting the "eventoGenerico", as though it doesn't exist in the working memory (it exists actually, and another rule sets the eventoGenerico to traductor previously):

Exception executing consequence for rule "Término sin Traducción" in RULA_PROV.SYSTEM_RULES: [Error: drools.retract( eventoGenerico ): null]
[Near : {... System.out.println("Evento gen ....}]
             ^
[Line: 1, Column: 1]
        at org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39)
        at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1297)

However, if I make this little change it works fine (this verifies that the eventoGenerico really exists in the working memory):

rule "Término sin Traducción"
    salience -100
    dialect "mvel"
    when
        traductor : TraductorDeEventosTratados()
            eventoGenerico : EventoGenerico()
            eventoGenerico2 : EventoGenerico( this == eventoGenerico ) from traductor.eventoGenerico
    then
        System.out.println("Evento generico: " + eventoGenerico);
            traductor.setEventoGenerico( null );
            update( traductor );
            retract( eventoGenerico );
end

It looks like a bug, any ideas?

Thanks in advance

Upvotes: 0

Views: 2756

Answers (2)

Esteban Aliverti
Esteban Aliverti

Reputation: 6322

This appears to be a bug in Drools 5.5 caused by the usage of mvel dialect. I managed to reproduce your error using this simple test:

Java:

Model model = new Model("Model A");
DataSample data = new DataSample(model);
ksession.insert(model);
ksession.insert(data);

ksession.fireAllRules();

Drools:

rule "Rule 1"
dialect "mvel"
when
    $d: DataSample()
    $m: Model() from $d.model
then
    $d.setModel(null);
    update($d);
    retract($m);
end

If you remove the dialect "mvel" modifier, the rule works as expected. Recently in Drools' mailing list there were some bug reports regarding mvel. Maybe this is one of them.

Best Regards,

Upvotes: 1

Steve
Steve

Reputation: 9490

You could retract(traductor), but not eventoGenerico.

The problem is that eventoGenerico is a property of your 'traductor' fact. You can't retract it, because you are not referencing the fact in working memory.

You did insert an EventoGenerico object as a separate fact, but it's only in the second (working) example that you have referenced it and are therefore able to retract it.

Upvotes: 1

Related Questions