Hi Drools Team,
We've encountered a critical issue with MVEL dialect in Drools 10 where .equals() method calls on string literals within eval() expressions fail on first execution but work correctly on subsequent executions. Using the == operator instead resolves the issue immediately.
When using MVEL dialect with eval() containing .equals() on string literal constants, rules fail to fire on first execution but work correctly on second and subsequent executions.
Observed Behavior:
First execution: eval("Y".equals("Y")) returns false or null → 0 rules fire
Second execution: Expression cache is warmed up → Rules fire correctly
All subsequent executions: Work correctly
Observed Behavior:
All executions: Work correctly from first execution onwards
Based on our investigation, the issue appears to be related to MVEL's constant expression optimization in Drools 10:
With .equals() method call:
MVEL attempts to pre-compile "Y".equals("Y") as a constant expression
During first compilation, the method reference is not fully initialized
The cached expression returns incorrect result (null or false)
On second execution, the cached expression is warmed up and works correctly
With == operator:
MVEL uses native operator evaluation (no method compilation needed)
No reflection or method resolution required
Works immediately on first execution
Drools Version: 10.x
Dialect: MVEL
Expression Type: eval() with string literal constants
Pattern: Decision table generated rules with constant checks
Java Version: 11+
Is this a known issue with MVEL constant optimization in Drools 10?
Is there a configuration to disable aggressive constant folding for .equals() calls?
Should we consider this a bug or expected MVEL behavior?
What is the recommended approach for decision tables that generate constant comparisons?
Are there plans to address this in future Drools releases?
This issue affects production systems where rules must fire correctly on first execution (e.g., first user login, cold start scenarios, batch processing). The workaround using == is simple but requires updating all affected decision tables and rules.
The issue is reproducible across different rule packages
It affects decision table generated rules where constant checks are common
Dummy fireAllRules() before actual execution does NOT resolve the issue (both return 0)
The problem is specific to string literal .equals() calls, not variable comparisons
Any insights or guidance would be greatly appreciated!
Best regards,
Development Team