fix problem with multiple method overrides in generic types.

This commit is contained in:
tueem 2024-11-29 21:41:18 +01:00
parent 239e921e6f
commit b7333c2e5e
Signed by: tueem
GPG Key ID: 65C8667EC17A88FB

@ -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;