Uploaded image for project: 'Drools'
  1. Drools
  2. DROOLS-3477

MVEL: expression (1 + 2 * 3 + 4 * $v ) causes "no such method or function " for bind variable

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • None
    • 7.11.0.Final
    • core engine
    • None
    • 2019 Week 02-04
    • Hide

      $ unzip mvel2-var-test2.zip
      $ cd mvel2-var-test2
      $ mvn clean test

      results:

      -------------------------------------------------------
       T E S T S
      -------------------------------------------------------
      Running com.sample.MvelVarTest
      
      ### MVel2 var NG Test ###
      ----------
      package com.sample;
      
      import com.sample.Message;
      dialect "mvel"
      rule "Hello World"
      when
           m : Message()
      then
            m.setStatus( 1 + 2 * 3 + 4 * m.getStatus() );
      end
      
      -----------
      Exception executing consequence for rule "Hello World" in com.sample: [Error: no such method or function: m]
      [Near : {... m.setStatus( 1 + 2 * 3 + 4 * m.getStatus() ); ....}]
                                                  ^
      [Line: 1, Column: 32]
      	at org.drools.core.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39)
      	at org.drools.core.common.DefaultAgenda.handleException(DefaultAgenda.java:1247)
      	at org.drools.core.phreak.RuleExecutor.innerFireActivation(RuleExecutor.java:438)
      	at org.drools.core.phreak.RuleExecutor.fireActivation(RuleExecutor.java:379)
      	at org.drools.core.phreak.RuleExecutor.fire(RuleExecutor.java:135)
      	at org.drools.core.phreak.RuleExecutor.evaluateNetworkAndFire(RuleExecutor.java:88)
      	at org.drools.core.concurrent.AbstractRuleEvaluator.internalEvaluateAndFire(AbstractRuleEvaluator.java:34)
      	at org.drools.core.concurrent.SequentialRuleEvaluator.evaluateAndFire(SequentialRuleEvaluator.java:43)
      	at org.drools.core.common.DefaultAgenda.fireLoop(DefaultAgenda.java:1067)
      	at org.drools.core.common.DefaultAgenda.internalFireAllRules(DefaultAgenda.java:1014)
      	at org.drools.core.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1006)
      	at org.drools.core.impl.StatefulKnowledgeSessionImpl.internalFireAllRules(StatefulKnowledgeSessionImpl.java:1321)
      	at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1312)
      	at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1296)
      	at com.sample.MvelVarTest.ngTest(MvelVarTest.java:38)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.lang.reflect.Method.invoke(Method.java:498)
      	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
      	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
      	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
      	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
      	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
      	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
      	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
      	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
      	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
      	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
      	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
      	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
      	at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
      	at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
      	at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.lang.reflect.Method.invoke(Method.java:498)
      	at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
      	at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
      	at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
      	at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
      	at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
      Caused by: [Error: no such method or function: m]
      [Near : {... m.setStatus( 1 + 2 * 3 + 4 * m.getStatus() ); ....}]
                                                  ^
      [Line: 1, Column: 32]
      	at org.mvel2.PropertyAccessor.getMethod(PropertyAccessor.java:897)
      	at org.mvel2.PropertyAccessor.getBeanProperty(PropertyAccessor.java:672)
      	at org.mvel2.PropertyAccessor.getBeanPropertyAO(PropertyAccessor.java:556)
      	at org.mvel2.PropertyAccessor.getAllowOverride(PropertyAccessor.java:209)
      	at org.mvel2.PropertyAccessor.get(PropertyAccessor.java:148)
      	at org.mvel2.PropertyAccessor.get(PropertyAccessor.java:125)
      	at org.mvel2.ast.ASTNode.getReducedValue(ASTNode.java:187)
      	at org.mvel2.compiler.AbstractParser.arithmeticFunctionReduction(AbstractParser.java:2432)
      	at org.mvel2.compiler.ExpressionCompiler.compileReduce(ExpressionCompiler.java:329)
      	at org.mvel2.compiler.ExpressionCompiler._compile(ExpressionCompiler.java:180)
      	at org.mvel2.util.ParseTools.subCompileExpression(ParseTools.java:2078)
      	at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:970)
      	at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:396)
      	at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.optimizeAccessor(ReflectiveAccessorOptimizer.java:163)
      	at org.mvel2.ast.ASTNode.optimize(ASTNode.java:159)
      	at org.mvel2.ast.ASTNode.getReducedValueAccelerated(ASTNode.java:115)
      	at org.mvel2.MVELRuntime.execute(MVELRuntime.java:85)
      	at org.mvel2.compiler.CompiledExpression.getDirectValue(CompiledExpression.java:123)
      	at org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:119)
      	at org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:113)
      	at org.mvel2.MVEL.executeExpression(MVEL.java:929)
      	at org.drools.core.base.mvel.MVELConsequence.evaluate(MVELConsequence.java:110)
      	at org.drools.core.phreak.RuleExecutor.innerFireActivation(RuleExecutor.java:431)
      	... 41 more
      
      ### MVel2 var OK Test ###
      ----------
      package com.sample;
      
      import com.sample.Message;
      dialect "mvel"
      rule "Hello World"
      when
           m : Message()
      then
            m.setStatus( 1 + 2 * 3 + m.getStatus() );
      end
      
      -----------
      Tests run: 2, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 1.274 sec <<< FAILURE!
      ngTest(com.sample.MvelVarTest)  Time elapsed: 1.104 sec  <<< FAILURE!
      java.lang.AssertionError
      	at org.junit.Assert.fail(Assert.java:86)
      	at org.junit.Assert.fail(Assert.java:95)
      	at com.sample.MvelVarTest.ngTest(MvelVarTest.java:43)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.lang.reflect.Method.invoke(Method.java:498)
      	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
      	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
      	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
      	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
      	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
      	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
      	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
      	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
      	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
      	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
      	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
      	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
      	at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
      	at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
      	at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.lang.reflect.Method.invoke(Method.java:498)
      	at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
      	at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
      	at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
      	at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
      	at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
      
      
      Results :
      
      Failed tests:   ngTest(com.sample.MvelVarTest)
      
      Tests run: 2, Failures: 1, Errors: 0, Skipped: 0
      
      
      Show
      $ unzip mvel2-var-test2.zip $ cd mvel2-var-test2 $ mvn clean test results: ------------------------------------------------------- T E S T S ------------------------------------------------------- Running com.sample.MvelVarTest ### MVel2 var NG Test ### ---------- package com.sample; import com.sample.Message; dialect "mvel" rule "Hello World" when m : Message() then m.setStatus( 1 + 2 * 3 + 4 * m.getStatus() ); end ----------- Exception executing consequence for rule "Hello World" in com.sample: [Error: no such method or function: m] [Near : {... m.setStatus( 1 + 2 * 3 + 4 * m.getStatus() ); ....}] ^ [Line: 1, Column: 32] at org.drools.core.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39) at org.drools.core.common.DefaultAgenda.handleException(DefaultAgenda.java:1247) at org.drools.core.phreak.RuleExecutor.innerFireActivation(RuleExecutor.java:438) at org.drools.core.phreak.RuleExecutor.fireActivation(RuleExecutor.java:379) at org.drools.core.phreak.RuleExecutor.fire(RuleExecutor.java:135) at org.drools.core.phreak.RuleExecutor.evaluateNetworkAndFire(RuleExecutor.java:88) at org.drools.core.concurrent.AbstractRuleEvaluator.internalEvaluateAndFire(AbstractRuleEvaluator.java:34) at org.drools.core.concurrent.SequentialRuleEvaluator.evaluateAndFire(SequentialRuleEvaluator.java:43) at org.drools.core.common.DefaultAgenda.fireLoop(DefaultAgenda.java:1067) at org.drools.core.common.DefaultAgenda.internalFireAllRules(DefaultAgenda.java:1014) at org.drools.core.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1006) at org.drools.core.impl.StatefulKnowledgeSessionImpl.internalFireAllRules(StatefulKnowledgeSessionImpl.java:1321) at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1312) at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1296) at com.sample.MvelVarTest.ngTest(MvelVarTest.java:38) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252) at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141) at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189) at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165) at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85) at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115) at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75) Caused by: [Error: no such method or function: m] [Near : {... m.setStatus( 1 + 2 * 3 + 4 * m.getStatus() ); ....}] ^ [Line: 1, Column: 32] at org.mvel2.PropertyAccessor.getMethod(PropertyAccessor.java:897) at org.mvel2.PropertyAccessor.getBeanProperty(PropertyAccessor.java:672) at org.mvel2.PropertyAccessor.getBeanPropertyAO(PropertyAccessor.java:556) at org.mvel2.PropertyAccessor.getAllowOverride(PropertyAccessor.java:209) at org.mvel2.PropertyAccessor.get(PropertyAccessor.java:148) at org.mvel2.PropertyAccessor.get(PropertyAccessor.java:125) at org.mvel2.ast.ASTNode.getReducedValue(ASTNode.java:187) at org.mvel2.compiler.AbstractParser.arithmeticFunctionReduction(AbstractParser.java:2432) at org.mvel2.compiler.ExpressionCompiler.compileReduce(ExpressionCompiler.java:329) at org.mvel2.compiler.ExpressionCompiler._compile(ExpressionCompiler.java:180) at org.mvel2.util.ParseTools.subCompileExpression(ParseTools.java:2078) at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:970) at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:396) at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.optimizeAccessor(ReflectiveAccessorOptimizer.java:163) at org.mvel2.ast.ASTNode.optimize(ASTNode.java:159) at org.mvel2.ast.ASTNode.getReducedValueAccelerated(ASTNode.java:115) at org.mvel2.MVELRuntime.execute(MVELRuntime.java:85) at org.mvel2.compiler.CompiledExpression.getDirectValue(CompiledExpression.java:123) at org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:119) at org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:113) at org.mvel2.MVEL.executeExpression(MVEL.java:929) at org.drools.core.base.mvel.MVELConsequence.evaluate(MVELConsequence.java:110) at org.drools.core.phreak.RuleExecutor.innerFireActivation(RuleExecutor.java:431) ... 41 more ### MVel2 var OK Test ### ---------- package com.sample; import com.sample.Message; dialect "mvel" rule "Hello World" when m : Message() then m.setStatus( 1 + 2 * 3 + m.getStatus() ); end ----------- Tests run: 2, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 1.274 sec <<< FAILURE! ngTest(com.sample.MvelVarTest) Time elapsed: 1.104 sec <<< FAILURE! java.lang.AssertionError at org.junit.Assert.fail(Assert.java:86) at org.junit.Assert.fail(Assert.java:95) at com.sample.MvelVarTest.ngTest(MvelVarTest.java:43) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252) at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141) at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189) at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165) at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85) at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115) at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75) Results : Failed tests: ngTest(com.sample.MvelVarTest) Tests run: 2, Failures: 1, Errors: 0, Skipped: 0
    • Hide

      change the following expression

      m.setStatus( 1 + 2 * 3 + 4 * m.getStatus() );

      to

      m.setStatus( 1 + 2 * 3 + (4 * m.getStatus()) );

      Show
      change the following expression m.setStatus( 1 + 2 * 3 + 4 * m.getStatus() ); to m.setStatus( 1 + 2 * 3 + (4 * m.getStatus()) );
    • NEW
    • NEW

      Similar issue was reported and fixed in DROOLS-2854, there is another pattern which does not work.
      When MVEL evaluates

      m.setStatus( 1 + 2 * 3 + 4 * m.getStatus() );

      the following exception happens.

      Exception executing consequence for rule "Hello World" in com.sample: [Error: no such method or function: m]
      [Near : {... m.setStatus( 1 + 2 * 3 + 4 * m.getStatus() ); ....}]
      

              mfusco@redhat.com Mario Fusco
              rhn-support-hmiura Hiroko Miura
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: