apache / incubator-kie-drools

Drools is a rule engine, DMN engine and complex event processing (CEP) engine for Java.
http://www.drools.org
5.85k stars 2.49k forks source link

Evaluate property reactive "firstProp" in calculateMaskFromExpression #6092

Open tkobayas opened 2 weeks ago

tkobayas commented 2 weeks ago

https://kie.zulipchat.com/#narrow/stream/232677-drools/topic/Static.20method.20in.20LHS

rule "cycle"
    when
        o1 : Object1( !Objects.isNull(field1) )
    then
        modify( o1 ) {
            setField2( "U" )
        }
end

With drools 8.44.0.Final, this rule causes a infinite loop, because in MVELConstraint.calculateMaskFromExpression, if firstProp (in this case, Objects) is not resolved as a fact's property, it results in allSetBitMask.

However, if we use static import,

import static java.util.Objects.isNull;

rule "cycle"
    when
        o1 : Object1( !isNull(field1) )
    then
        System.out.println("Rule cycle fired");
        modify( o1 ) {
            setField2( "U" )
        }
end

we can work around the problem and make it property reactive for only field1. (Method call arguments are reactive since 7.46.0 : https://docs.drools.org/7.73.0.Final/drools-docs/html_single/#better-property-reactivity )

Do we need such firstProp restriction? Consider use cases which requires firstProp and backward compatibility impact. Maybe we can check all props and then use allSetBitMask only when there is no valid prop.

Of course, also consider the consistency with exec-model.