I wanted to raise a concern regarding rule compilation behavior in Drools, specifically around variable binding and constraint evaluation.
We observed a scenario where a rule compiles successfully but produces incorrect runtime behavior due to missing $ in variable bindings. Ideally, such cases should fail during compilation rather than silently executing with unintended logic.
ExampleBefore (compiles but behaves incorrectly):
rule "SampleRule"In this case:
fieldA == fieldA becomes a self-comparison, always true
The rule fires incorrectly for all facts
After correction (expected behavior):
rule "SampleRule"Here:
$fieldB is properly bound and used
Constraint behaves as intended
The issue is that the incorrect version:
Compiles without any warning or error
Leads to logically incorrect rule execution
Is difficult to detect, especially in large rule bases
Is there any existing mechanism (or roadmap plan) in Drools to:
Detect self-comparisons like:
fieldA == fieldAValidate usage of bound variables vs unbound fields
Provide compile-time warnings or strict mode for such cases
Even a warning-level validation would significantly help prevent subtle production issues.
In large-scale rule systems, especially during migrations or automated transformations, such issues are hard to catch and can lead to incorrect business outcomes without obvious failures.
Appreciate your guidance on whether such validation exists or if there are recommended best practices/tools to detect these cases.
Thanks,
Geeta.
--
You received this message because you are subscribed to the Google Groups "Drools Usage" group.
To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/drools-usage/e718ba54-d61a-46fd-a42d-431cca857551n%40googlegroups.com.