Uploaded image for project: 'Commons OGNL (Dormant)'
  1. Commons OGNL (Dormant)
  2. OGNL-160

java.lang.NoSuchMethodException when call to method prefers private method that is more specific than public method

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 2.7.3, 3.0
    • None
    • Core Runtime
    • None

    Description

      I have the following simple expression:

      "doSomething(#a)"

      where #a is an object of AImpl class that implements A interface passed through the context that implements an interface; the method "doSomething" is called on a source object that has two methods with following signature:

      public Object doSomething(A a); <<---- public method

      private Object doSomething(AImpl impl) <<---- private method

      When OgnlRuntime searches for "doSomething" appropriate method, it finds the one with AImpl argument because is the more specific that the public one, but is inaccessible because of private modifier.

      Probably searching for appropriate method, should consider the access modifier.

      Following is a test for the problem I've noticed.

      public class TestAccess {

      public interface A

      { public String greets(String name); }

      public class AImpl implements A {

      public String greets(String name)

      { return "Hello " + name; }

      }

      public class B {

      private Object doSomething(AImpl impl)

      { return impl.greets("test user"); }

      public Object doSomething(A a)

      { return doSomething((AImpl) a); }

      }

      public static void main(String[] args) throws Exception

      { TestAccess t = new TestAccess(); A a = t.new AImpl(); B b1 = t.new B(); System.out.println("Without OGNL result: " + b1.doSomething(a)); OgnlContext defaultContext = (OgnlContext) Ognl .createDefaultContext(null); defaultContext.put("a", a); B b = t.new B(); Object result = Ognl.getValue(Ognl.parseExpression("doSomething(#a)"), defaultContext, b); System.out.println("With OGNL result: " + result); }

      }

      Greetings,

      Nunzio La Riviera

      Attachments

        Activity

          People

            jkuhnert Jesse Kuhnert
            xnunziox Nunzio La Riviera
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: