Skip to content

Variable scope issues when executing MVEL rules #27

@alexciouca

Description

@alexciouca

Describe the bug
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'

To Reproduce
I attached a test class and the necessary .yml files to quickly reproduce the issues.

Expected behavior
The use cases run without issues and no exceptions are thrown.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions