From 9b35401483e86dfa297431fbfe41b91581fa94ae Mon Sep 17 00:00:00 2001 From: Basil Crow Date: Sun, 27 Oct 2024 09:13:00 -0700 Subject: [PATCH] Handle base=derived case in `Util#isOverridden` (#598) --- core/src/main/java/org/kohsuke/stapler/ReflectionUtils.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/src/main/java/org/kohsuke/stapler/ReflectionUtils.java b/core/src/main/java/org/kohsuke/stapler/ReflectionUtils.java index 929d16eb1..0e4c96a33 100644 --- a/core/src/main/java/org/kohsuke/stapler/ReflectionUtils.java +++ b/core/src/main/java/org/kohsuke/stapler/ReflectionUtils.java @@ -101,6 +101,10 @@ public static Annotation[] union(Annotation[] a, Annotation[] b) { */ public static boolean isOverridden( @NonNull Class base, @NonNull Class derived, @NonNull String methodName, @NonNull Class... types) { + if (base == derived) { + // If base and derived are the same type, the method is not overridden by definition + return false; + } // If derived is not a subclass or implementor of base, it can't override any method // Technically this should also be triggered when base == derived, because it can't override its own method, but // the unit tests explicitly test for that as working.