Skip to content

Commit

Permalink
fix for issue #29 - Ognl.GetMethods does not return default methods from
Browse files Browse the repository at this point in the history
interfaces implemented by parent class
  • Loading branch information
vlastimil-dolejs committed Sep 20, 2016
1 parent 16d81b2 commit ca37319
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/java/ognl/OgnlRuntime.java
Original file line number Diff line number Diff line change
Expand Up @@ -1789,9 +1789,10 @@ public static Map getMethods(Class targetClass, boolean staticMethods)
for (Class c = targetClass; c != null; c = c.getSuperclass())
{
toExamined.add(c);

// Including interfaces is needed as from Java 8 intefaces can implement defaul methods
toExamined.addAll(Arrays.asList(c.getInterfaces()));
}
// Including interfaces is needed as from Java 8 intefaces can implement defaul methods
toExamined.addAll(Arrays.asList(targetClass.getInterfaces()));

for (Class c : toExamined)
{
Expand Down
24 changes: 19 additions & 5 deletions src/test/java/ognl/Java8Test.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,37 @@
package ognl;

import java.util.List;

import junit.framework.TestCase;

import java.util.List;
public class Java8Test extends TestCase {

public class Java8Test extends TestCase /* implements InterfaceWithDefaults */ {
public void testDefaultMethodOnClass() {
/* defaultMethod(); */
List defaultMethod = OgnlRuntime.getMethods(ClassWithDefaults.class, "defaultMethod", false);
assertNotNull(defaultMethod);
}

public void testDefaultMethod() {
public void testDefaultMethodOnSubClass() {
/* defaultMethod(); */
List defaultMethod = OgnlRuntime.getMethods(Java8Test.class, "defaultMethod", false);
List defaultMethod = OgnlRuntime.getMethods(SubClassWithDefaults.class, "defaultMethod", false);
assertNotNull(defaultMethod);
}

}

class SubClassWithDefaults extends ClassWithDefaults {

}

class ClassWithDefaults /* implements InterfaceWithDefaults */ {

}

/**
* This won't work till switching to Java 8
*
interface InterfaceWithDefaults {
default public void defaultMethod() { }
}
*/
*/

0 comments on commit ca37319

Please sign in to comment.