Skip to content

Commit

Permalink
Ports IllegalArgumentException : Can't decide wich method to use fix
Browse files Browse the repository at this point in the history
This refers to #159
  • Loading branch information
lukaszlenart committed Jul 15, 2022
1 parent 9915d6a commit dd2c581
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main/java/org/ognl/OgnlRuntime.java
Original file line number Diff line number Diff line change
Expand Up @@ -1453,6 +1453,10 @@ private static MatchingMethod findBestMethod(List<Method> methods, Class<?> type
scoreOther += 100; // current wins...
} else if (moClass == argClass) {
scoreCurr += 100; // other wins...
} else if (mcClass.isAssignableFrom(moClass)) {
scoreOther += 50; // current wins...
} else if (moClass.isAssignableFrom(moClass)) {
scoreCurr += 50; // other wins...
} else {
// both items can't be assigned to each other..
// TODO: if this happens we have to put some weight on the inheritance...
Expand Down
10 changes: 10 additions & 0 deletions src/test/java/org/ognl/OgnlRuntimeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
Expand Down Expand Up @@ -609,4 +610,13 @@ public Long get() {
Assert.assertEquals(3L,
Ognl.getValue("get()", defaultContext, new C1()));
}

@Test
public void shouldSameMethodOfDifferentParentsBeCallable() throws Exception {
Map<String, Object> root = new HashMap<>();
root.put("d1", java.sql.Date.valueOf("2022-01-01"));
root.put("d2", java.sql.Date.valueOf("2022-01-02"));
Assert.assertEquals(-1, Ognl.getValue("d1.compareTo(d2)", defaultContext, root));
}

}

0 comments on commit dd2c581

Please sign in to comment.