MVEL
  1. MVEL
  2. MVEL-272

RuntimeException "can't write to function" that only occurs on second execution using compiled expression but never using veal

    Details

    • Type: Bug Bug
    • Status: Open Open
    • Priority: Critical Critical
    • Resolution: Unresolved
    • Affects Version/s: 2.0.19
    • Fix Version/s: None
    • Component/s: Core
    • Labels:
      None
    • Number of attachments :
      0

      Description

      evaluate("xpath('/root').attributes['newAttr']=1", message);
      evaluate("xpath('/root').attributes['newAttr']=1", message);
      

      The first time around this expression updates the DOM4J node returned by my xpath() function correctly. The second time it fails with a "can't write to function" RuntimeException. If I use MVEL.eval() that this doesn't occur. Also if i disable my compiled expression cache then things work too.

      The root cause from what I can see is that the CompiledExpression is being mutated the on the first execution and this then affects the behavior of any further execution.

      I've found the place where this happens:

      org.mvel2.compiler.CompiledAccExpression.setValue(Object, Object, VariableResolverFactory, Object)

      While getThreadAccessorOptimizer().optimizeSetAccessor(context, expression, 0, expression.length, ctx, ctx, vrf, false, value, ingressType); does exactly what it needed, the Accessor returned which is then in affect cached in the CompiledAccExpression instance does not and tries assigning '1' to the function directly thus failing.

      It seems strange or maybe even incorrect that CompiledExpression is being mutated, especially if it changes it's behavior on subsequent executions.

        Activity

        Hide
        Daniel Feist added a comment -

        I forgot to mention that I have a property handler registered for DOM4J element which returns a map wrapping the elements attributes in a map. Thus the syntax you see.

        Show
        Daniel Feist added a comment - I forgot to mention that I have a property handler registered for DOM4J element which returns a map wrapping the elements attributes in a map. Thus the syntax you see.

          People

          • Assignee:
            Mike Brock
            Reporter:
            Daniel Feist
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated: