apache / incubator-kie-drools

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

Difference when using redundant variable qualifier and not using it (with MVEL runtime, MVEL syntax) #5943

Closed flozano closed 6 months ago

flozano commented 6 months ago

Description

While testing #5925 I identified a case in which:

    when
        $v:drools.issues.model.vehicles.GasolineVehicle(motor.highOctane == true, score<=1, $v.motor.serialNumber > 50000)

and

    when
        $v:drools.issues.model.vehicles.GasolineVehicle(motor.highOctane == true, score<=1, motor.serialNumber > 50000)

don't behave the same. Strangely enough, only motor.serialNumber > 50000 has an effect, qualifying or un-qualifying the other clauses do not make any difference.

Also, only happens with the dynamically generated model. In the process of #5925 I added identical test for both dynamic (byte-buddy) and normally-compiled code, and there was no difference in that issue, but in this one there is.

How to reproduce

This test https://github.com/flozano/drools-issues/blob/main/src/test/java/drools/issues/DynamicClassTest.java Uses these two DRL files:

In the second one (java compiled code), the $v can be added/removed with no issue. In the first one (byte-buddy model, currently $v.motor.serialNumber > 50000 is used - and the test pass. If $v. is removed from that clause, the test does not pass.

(https://github.com/flozano/drools-issues/commit/3f9c53172e9998905b0ed9e82ce449edda544f2d)

flozano commented 6 months ago

(please note that the latest commit is needed to reproduce properly)

mariofusco commented 6 months ago

Fixed by https://github.com/apache/incubator-kie-drools/commit/664511036b3562fa11f333810990570705cb52dd