{"action":"created","issue":{"url":"https://api.github.com/repos/ronmamo/reflections/issues/23","labels_url":"https://api.github.com/repos/ronmamo/reflections/issues/23/labels{/name}","comments_url":"https://api.github.com/repos/ronmamo/reflections/issues/23/comments","events_url":"https://api.github.com/repos/ronmamo/reflections/issues/23/events","html_url":"https://github.com/ronmamo/reflections/issues/23","id":31013529,"number":23,"title":"withParametersAssignableTo","user":{"login":"jpmorin","id":967808,"avatar_url":"https://avatars.githubusercontent.com/u/967808?v=3","gravatar_id":"","url":"https://api.github.com/users/jpmorin","html_url":"https://github.com/jpmorin","followers_url":"https://api.github.com/users/jpmorin/followers","following_url":"https://api.github.com/users/jpmorin/following{/other_user}","gists_url":"https://api.github.com/users/jpmorin/gists{/gist_id}","starred_url":"https://api.github.com/users/jpmorin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jpmorin/subscriptions","organizations_url":"https://api.github.com/users/jpmorin/orgs","repos_url":"https://api.github.com/users/jpmorin/repos","events_url":"https://api.github.com/users/jpmorin/events{/privacy}","received_events_url":"https://api.github.com/users/jpmorin/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2014-04-07T19:17:34Z","updated_at":"2015-05-06T12:47:09Z","closed_at":"2014-06-02T17:23:31Z","body":"The withParametersAssignableTo Predicate seems to have a problem. The isAssignableFrom check is done backward.\r\n\r\n```java\r\n// from \"org.reflections.ReflectionUtils.withParametersAssignableTo(final Class... types)\", line 246\r\nif (!types[i].isAssignableFrom(parameterTypes[i])) {\r\n     return false;\r\n}\r\n```\r\n\r\nIn the exemple above, types represents the Class<?>[] parameter passed to the predicate, while parameterTypes is retreive from the Method's signature.\r\n\r\nThe isAssignableFrom check should be done from the method's parameter type, with the parameter type received has arguments.\r\n\r\n```java\r\n// fixed\r\nif (!parameterTypes[i].isAssignableFrom(types[i])) {\r\n     return false;\r\n}\r\n```\r\n\r\nHere's my sample usecase:\r\n\r\n```java\r\nimport static org.reflections.ReflectionUtils.getMethods;\r\nimport static org.reflections.ReflectionUtils.withParametersAssignableTo;\r\n\r\nimport java.lang.reflect.Method;\r\nimport java.util.Set;\r\n\r\npublic class ReflectionTest {\r\n\r\n\tprivate interface IFruit {}\r\n\t\r\n\tpublic class Apple implements IFruit {}\r\n\tpublic class Orange implements IFruit {}\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\tnew ReflectionTest();\r\n\t}\r\n\t\r\n\tpublic ReflectionTest() {\r\n\t\tboolean a = IFruit.class.isAssignableFrom(Apple.class);\r\n\t\tboolean b = IFruit.class.isAssignableFrom(Orange.class);\r\n\t\tboolean c = Apple.class.isAssignableFrom(IFruit.class);\r\n\t\tboolean d = Orange.class.isAssignableFrom(IFruit.class);\r\n\r\n\t\tSystem.out.println(a); // true\r\n\t\tSystem.out.println(b); // true\r\n\t\tSystem.out.println(c); // false\r\n\t\tSystem.out.println(d); // false\r\n\r\n\t\tExemple(new Apple()); // class ReflectionTest$Apple\r\n\t\tExemple(new Orange()); // class ReflectionTest$Orange\r\n\r\n\t\t// Currently this returns an empty Set<Method> but it should return the a Set with a size of 1 containing the\r\n\t\t// Exemple(IFruit) Method object.\r\n\t\tSet<Method> methods = getMethods(ReflectionTest.class, withParametersAssignableTo(new Class<?>[] { Apple.class }));\r\n\r\n\t\tSystem.out.println(methods.size()); // 0\r\n\t}\r\n\r\n\tpublic void Exemple(IFruit fruit) {\r\n\t\tSystem.out.println(fruit.getClass());\r\n\t}\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/ronmamo/reflections/issues/comments/99437249","html_url":"https://github.com/ronmamo/reflections/issues/23#issuecomment-99437249","issue_url":"https://api.github.com/repos/ronmamo/reflections/issues/23","id":99437249,"user":{"login":"monku","id":857341,"avatar_url":"https://avatars.githubusercontent.com/u/857341?v=3","gravatar_id":"","url":"https://api.github.com/users/monku","html_url":"https://github.com/monku","followers_url":"https://api.github.com/users/monku/followers","following_url":"https://api.github.com/users/monku/following{/other_user}","gists_url":"https://api.github.com/users/monku/gists{/gist_id}","starred_url":"https://api.github.com/users/monku/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/monku/subscriptions","organizations_url":"https://api.github.com/users/monku/orgs","repos_url":"https://api.github.com/users/monku/repos","events_url":"https://api.github.com/users/monku/events{/privacy}","received_events_url":"https://api.github.com/users/monku/received_events","type":"User","site_admin":false},"created_at":"2015-05-06T12:47:09Z","updated_at":"2015-05-06T12:47:09Z","body":"Hi sorry to break this that late, but previous behavior was correct.\r\n\r\nI just upgraded from 0.9.8 to 0.9.9 and found out that this method got broken.\r\n\r\nClass ReflectionTest HAS 0 methods with parameters assgnable *TO* Orange.class (No method with arguments that are subclasses of Orange).\r\n\r\nIt has 1 method with  parameters assignable *FROM* \"Orange.class\"\r\n\r\nSo right now ReflectionUtils.withParametersAssignableTo should either be reverted or reven better add a method with name \"withParametersAssignableFrom\"\r\n\r\n"}}