From b7333c2e5e92790fae201349aec1b59cd45e7cd7 Mon Sep 17 00:00:00 2001 From: tueem Date: Fri, 29 Nov 2024 21:41:18 +0100 Subject: [PATCH] fix problem with multiple method overrides in generic types. --- .../net/tomatentum/marinara/checks/AppliedCheck.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/src/main/java/net/tomatentum/marinara/checks/AppliedCheck.java b/lib/src/main/java/net/tomatentum/marinara/checks/AppliedCheck.java index 28415b0..4f969f2 100644 --- a/lib/src/main/java/net/tomatentum/marinara/checks/AppliedCheck.java +++ b/lib/src/main/java/net/tomatentum/marinara/checks/AppliedCheck.java @@ -12,11 +12,12 @@ public record AppliedCheck(InteractionCheck check, Annotation annotation) { public boolean pre(Object context) { Method[] methods = Arrays.stream(check.getClass().getMethods()) .filter(x -> x.getName().equals("preExec")) + .filter(x -> !x.isBridge()) .toArray(s -> new Method[s]); - Method method = ReflectionUtil.getMostSpecificMethod(methods, context.getClass()); + Method method = ReflectionUtil.getMostSpecificMethod(methods, context.getClass(), annotation.getClass()); method.setAccessible(true); try { - return (boolean) method.invoke(check, annotation); + return (boolean) method.invoke(check, context, annotation); } catch (IllegalAccessException | InvocationTargetException | SecurityException e) { e.printStackTrace(); return false; @@ -26,11 +27,12 @@ public record AppliedCheck(InteractionCheck check, Annotation annotation) { public boolean post(Object context) { Method[] methods = Arrays.stream(check.getClass().getMethods()) .filter(x -> x.getName().equals("postExec")) + .filter(x -> !x.isBridge()) .toArray(s -> new Method[s]); - Method method = ReflectionUtil.getMostSpecificMethod(methods, context.getClass()); + Method method = ReflectionUtil.getMostSpecificMethod(methods, context.getClass(), annotation.getClass()); method.setAccessible(true); try { - return (boolean) method.invoke(check, annotation); + return (boolean) method.invoke(check, context, annotation); } catch (IllegalAccessException | InvocationTargetException | SecurityException e) { e.printStackTrace(); return false;