@@ -118,7 +118,8 @@ public InstrumentationInfo lookupImplementationMethod(
118118 ) throws NoSuchMethodException , ClassNotFoundException {
119119
120120 var targetMethod = targetSuperclass .getDeclaredMethod (methodName , parameterTypes );
121- validateTargetMethod (implementationClass , targetMethod );
121+ var implementationMethod = implementationClass .getMethod (targetMethod .getName (), targetMethod .getParameterTypes ());
122+ validateTargetMethod (implementationClass , targetMethod , implementationMethod );
122123
123124 var checkerAdditionalArguments = Stream .of (Class .class , targetSuperclass );
124125 var checkMethodArgumentTypes = Stream .concat (checkerAdditionalArguments , Arrays .stream (parameterTypes ))
@@ -169,15 +170,15 @@ public MethodVisitor visitMethod(
169170
170171 return new InstrumentationInfo (
171172 new MethodKey (
172- Type .getInternalName (implementationClass ),
173- targetMethod .getName (),
173+ Type .getInternalName (implementationMethod . getDeclaringClass () ),
174+ implementationMethod .getName (),
174175 Arrays .stream (parameterTypes ).map (c -> Type .getType (c ).getInternalName ()).toList ()
175176 ),
176177 checkMethod [0 ]
177178 );
178179 }
179180
180- private static void validateTargetMethod (Class <?> implementationClass , Method targetMethod ) {
181+ private static void validateTargetMethod (Class <?> implementationClass , Method targetMethod , Method implementationMethod ) {
181182 if (targetMethod .getDeclaringClass ().isAssignableFrom (implementationClass ) == false ) {
182183 throw new IllegalArgumentException (
183184 String .format (
@@ -209,37 +210,26 @@ private static void validateTargetMethod(Class<?> implementationClass, Method ta
209210 )
210211 );
211212 }
212- try {
213- var implementationMethod = implementationClass .getMethod (targetMethod .getName (), targetMethod .getParameterTypes ());
214- var methodModifiers = implementationMethod .getModifiers ();
215- if (Modifier .isAbstract (methodModifiers )) {
216- throw new IllegalArgumentException (
217- String .format (
218- Locale .ROOT ,
219- "Not a valid instrumentation method: %s is abstract in %s" ,
220- targetMethod .getName (),
221- implementationClass .getName ()
222- )
223- );
224- }
225- if (Modifier .isPublic (methodModifiers ) == false ) {
226- throw new IllegalArgumentException (
227- String .format (
228- Locale .ROOT ,
229- "Not a valid instrumentation method: %s is not public in %s" ,
230- targetMethod .getName (),
231- implementationClass .getName ()
232- )
233- );
234- }
235- } catch (NoSuchMethodException e ) {
236- assert false
237- : String .format (
213+ var methodModifiers = implementationMethod .getModifiers ();
214+ if (Modifier .isAbstract (methodModifiers )) {
215+ throw new IllegalArgumentException (
216+ String .format (
238217 Locale .ROOT ,
239- "Not a valid instrumentation method: %s cannot be found in %s" ,
218+ "Not a valid instrumentation method: %s is abstract in %s" ,
240219 targetMethod .getName (),
241220 implementationClass .getName ()
242- );
221+ )
222+ );
223+ }
224+ if (Modifier .isPublic (methodModifiers ) == false ) {
225+ throw new IllegalArgumentException (
226+ String .format (
227+ Locale .ROOT ,
228+ "Not a valid instrumentation method: %s is not public in %s" ,
229+ targetMethod .getName (),
230+ implementationClass .getName ()
231+ )
232+ );
243233 }
244234 }
245235
0 commit comments