j-easy / easy-rules

The simple, stupid rules engine for Java
https://github.com/j-easy/easy-rules/wiki
MIT License
4.86k stars 1.05k forks source link

Variable scope issues when executing MVEL rules #362

Open adamGyure opened 3 years ago

adamGyure commented 3 years ago

Hello,

I am experiencing two issues regards to variable scopes when evaluating a rule's condition.

The first issue happens when I try to write a for loop inside another for loop. During execution, I get this error as soon as the outer for loop starts its second iteration: java.lang.RuntimeException: variable already defined within scope: int y

The second issue is more complicated and complex. It seems that if I define a variable in ruleA's condition, the variable somehow leaks to or rather invalidates the variable with the same name in ruleB's condition. Basically, I define chcks = []; in ruleA, then I define it in ruleB the same way, chcks = []; and get the following exception: org.mvel2.UnresolveablePropertyException: unable to resolve token: unable to resolve variable 'chcks'

I attached a test class and the necessary .yml files to quickly reproduce the issues. I used the latest master branch (as of today, 2021.09.06) for testing. Any help is much appreciated.

Thank you, Adam

MVELVariableScopesTest.java.txt variable-scope-working.yml.txt variable-overflow.yml.txt variable-overflow-working.yml.txt variable-scope.yml.txt