MVEL
  1. MVEL
  2. MVEL-186

If we didn't find anything, maybe we're looking for the actual java.lang.Class methods.

    Details

    • Type: New Feature New Feature
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0.12
    • Fix Version/s: 2.0.18
    • Component/s: None
    • Labels:
      None
    • Number of attachments :
      0

      Description

      I see following code in ReflectiveAccessorOptimizer.

      if (m == null) {
      /**

      • If we didn't find anything, maybe we're looking for the actual java.lang.Class methods.
        */
        if ((m = getBestCandidate(argTypes, name, cls, cls.getClass().getDeclaredMethods(), false)) != null) { parameterTypes = m.getParameterTypes(); }

        }

      As I understand, it allows to call any (even protected and private) method of Class.

      My problem is that I would like to use MVEL to call protected/private methods of objects.
      Right now MVEL checks only public methods:

      if ((m = getBestCandidate(argTypes, name, cls, cls.getMethods(), false)) != null)

      { parameterTypes = m.getParameterTypes(); }

      Is it possible to add some optional flag to configure MVEL to be "safe" for users or turn on "powerful" mode?
      For now in each such case I have to fall back to my ReflectionUtils, which is much more verbose and less convenient.
      I.e.


      Object menu = ReflectionUtils.invokeMethod(getObject(), "getParent()");
      ReflectionUtils.invokeMethod(
      menu,
      "onDeactivate(com.extjs.gxt.ui.client.widget.menu.MenuBarItem)",
      getObject());


      instead of short


      JavaInfoUtils.executeScript(this, "object.parent.onDeactivate(object)");


        Activity

        Hide
        Mike Brock added a comment -

        Will look into this when I get back from vacation.

        Show
        Mike Brock added a comment - Will look into this when I get back from vacation.
        Hide
        Konstantin Scheglov added a comment -

        Any news?
        I just ask.

        Show
        Konstantin Scheglov added a comment - Any news? I just ask.
        Hide
        Mike Brock added a comment -

        now fixed.

        Show
        Mike Brock added a comment - now fixed.
        Hide
        Konstantin Scheglov added a comment -

        Does mvel2-2.0.18-RC5.jar already include this fix?
        I can not make it work in this test.

        public void test_evaluate_withContextXXX() throws Exception {
        assertEquals(5, MVELUtils.evaluate("foo()", new Object() {
        private int foo()

        { return 5; }

        }));
        }

        [Error: unable to resolve method: com.instantiations.designer.core.model.util.MVELUtils_Test$1.foo() [arglength=0]]
        [Near :

        {... Unknown ....}

        ]
        ^
        [Line: 1, Column: 0]
        at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:962)
        at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:326)
        at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.optimizeAccessor(ReflectiveAccessorOptimizer.java:135)
        at org.mvel2.ast.ASTNode.getReducedValueAccelerated(ASTNode.java:139)
        at org.mvel2.MVELRuntime.execute(MVELRuntime.java:85)
        at org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:105)
        at org.mvel2.MVEL.executeExpression(MVEL.java:1039)
        at com.instantiations.designer.core.model.util.MVELUtils.evaluate(MVELUtils.java:91)
        at com.instantiations.designer.core.model.util.MVELUtils_Test.test_evaluate_withContextXXX(MVELUtils_Test.java:57)

        Show
        Konstantin Scheglov added a comment - Does mvel2-2.0.18-RC5.jar already include this fix? I can not make it work in this test. public void test_evaluate_withContextXXX() throws Exception { assertEquals(5, MVELUtils.evaluate("foo()", new Object() { private int foo() { return 5; } })); } [Error: unable to resolve method: com.instantiations.designer.core.model.util.MVELUtils_Test$1.foo() [arglength=0] ] [Near : {... Unknown ....} ] ^ [Line: 1, Column: 0] at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:962) at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:326) at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.optimizeAccessor(ReflectiveAccessorOptimizer.java:135) at org.mvel2.ast.ASTNode.getReducedValueAccelerated(ASTNode.java:139) at org.mvel2.MVELRuntime.execute(MVELRuntime.java:85) at org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:105) at org.mvel2.MVEL.executeExpression(MVEL.java:1039) at com.instantiations.designer.core.model.util.MVELUtils.evaluate(MVELUtils.java:91) at com.instantiations.designer.core.model.util.MVELUtils_Test.test_evaluate_withContextXXX(MVELUtils_Test.java:57)
        Hide
        Mike Brock added a comment -

        But that's because the method is private, and MVEL only looks for properly accessible methods. MVEL has always respected class security and encapsulation rules.

        Show
        Mike Brock added a comment - But that's because the method is private, and MVEL only looks for properly accessible methods. MVEL has always respected class security and encapsulation rules.
        Hide
        Konstantin Scheglov added a comment -

        Yes.
        But using private/protected methods was spirit of this request.
        See citation below.


        Is it possible to add some optional flag to configure MVEL to be "safe" for users or turn on "powerful" mode?

        In reality I don't understand now what was fixed.

        Show
        Konstantin Scheglov added a comment - Yes. But using private/protected methods was spirit of this request. See citation below. — Is it possible to add some optional flag to configure MVEL to be "safe" for users or turn on "powerful" mode? — In reality I don't understand now what was fixed.

          People

          • Assignee:
            Mike Brock
            Reporter:
            Konstantin Scheglov
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: