JEXL fails to find abstract public methods in the base class if overridden by 
non-public derived types
------------------------------------------------------------------------------------------------------

                 Key: JEXL-40
                 URL: https://issues.apache.org/jira/browse/JEXL-40
             Project: Commons JEXL
          Issue Type: Bug
    Affects Versions: 1.1
            Reporter: Kohsuke Kawaguchi


If I have a code that fits the following pattern:

{noformat}
public class Base {
  public abstract void foo();
}

class Derived extends Base {
  public void foo() {}
}
{noformat}

JEXL fails to discover the foo method on an instance of Derived, even if this 
method is invokable.

This is because in ClassMap.java, the populateMethodCache method reads:

{noformat}
// Some of the interfaces contain abstract methods. That is fine, because the 
actual object must
// implement them anyway (else it wouldn't be implementing the interface). If 
we find an abstract
// method in a non-interface, we skip it, because we do want to make sure that 
no abstract methods end up in
// the cache.
if (classToReflect.isInterface() || !Modifier.isAbstract(modifiers)) {
{noformat}

The problem can be fixed by simply getting rid this check and always do 
"methodCache.put(methods[i]);"

The comment above doesn't make much sense to me. First, interfaces only contain 
abstract methods by definition. And if interfaces are deemed OK, I don't see 
why abstract methods in the base classes are treated any differently. Given any 
instance that's assignable to the base type, under normal circumstances every 
abstract method is invokable. There's no difference between interfaces and base 
classes on this point.

(The only situation where abstract methods are not implemented is when class 
files were changed in incompatible way)

This pattern of having abstract methods in the base type to be implemented by 
non-public class is a common pattern. So I suggest we simply remove the if 
block shown above.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to