Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
2.7.3, 3.0
-
None
-
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