{"record":{"id":"2fb61baf40a6bd81","repo":"spring-projects/spring-framework","slug":"aop-configuration-seems-to-be-invalid-tried-calli","errorCode":null,"errorMessage":"AOP configuration seems to be invalid: tried calling method [{method}] on target [{target}]","messagePattern":"AOP configuration seems to be invalid: tried calling method \\[(.+?)\\] on target \\[(.+?)\\]","errorType":"exception","errorClass":"AopInvocationException","httpStatus":null,"severity":"error","filePath":"spring-aop/src/main/java/org/springframework/aop/support/AopUtils.java","lineNumber":367,"sourceCode":"\t * @throws org.springframework.aop.AopInvocationException in case of a reflection error\n\t */\n\tpublic static @Nullable Object invokeJoinpointUsingReflection(@Nullable Object target, Method method, @Nullable Object[] args)\n\t\t\tthrows Throwable {\n\n\t\t// Use reflection to invoke the method.\n\t\ttry {\n\t\t\tMethod originalMethod = BridgeMethodResolver.findBridgedMethod(method);\n\t\t\tReflectionUtils.makeAccessible(originalMethod);\n\t\t\treturn (COROUTINES_REACTOR_PRESENT && KotlinDetector.isSuspendingFunction(originalMethod) ?\n\t\t\t\t\tKotlinDelegate.invokeSuspendingFunction(originalMethod, target, args) : originalMethod.invoke(target, args));\n\t\t}\n\t\tcatch (InvocationTargetException ex) {\n\t\t\t// Invoked method threw a checked exception.\n\t\t\t// We must rethrow it. The client won't see the interceptor.\n\t\t\tthrow ex.getTargetException();\n\t\t}\n\t\tcatch (IllegalArgumentException ex) {\n\t\t\tthrow new AopInvocationException(\"AOP configuration seems to be invalid: tried calling method [\" +\n\t\t\t\t\tmethod + \"] on target [\" + target + \"]\", ex);\n\t\t}\n\t\tcatch (IllegalAccessException | InaccessibleObjectException ex) {\n\t\t\tthrow new AopInvocationException(\"Could not access method [\" + method + \"]\", ex);\n\t\t}\n\t}\n\n\n\t/**\n\t * Inner class to avoid a hard dependency on Kotlin at runtime.\n\t */\n\tprivate static class KotlinDelegate {\n\n\t\tpublic static Object invokeSuspendingFunction(Method method, @Nullable Object target, @Nullable Object... args) {\n\t\t\tContinuation<?> continuation = (Continuation<?>) args[args.length -1];\n\t\t\tAssert.state(continuation != null, \"No Continuation available\");\n\t\t\tCoroutineContext context = continuation.getContext().minusKey(Job.Key);\n\t\t\treturn CoroutinesUtils.invokeSuspendingFunction(context, method, target, args);","sourceCodeStart":349,"sourceCodeEnd":385,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/69bf83ad716d0cfc4b0520a19b4d8b24c79d1538/spring-aop/src/main/java/org/springframework/aop/support/AopUtils.java#L349-L385","documentation":"Thrown by AopUtils.invokeJoinpointUsingReflection (line 366-368) when Method.invoke raises an IllegalArgumentException. This happens when the method's declaring class does not match the target object's class, or the supplied argument array's types/counts do not match the method signature. The reflection error is wrapped in an AopInvocationException that names the method and target.","triggerScenarios":"An AOP interceptor calls invokeJoinpointUsingReflection with a Method obtained from a different class than 'target', or with mismatched args (wrong count, incompatible types, null for a primitive). Common when a proxy target is swapped, when bridged/generic methods are mishandled, or when an interceptor tampers with the argument array.","commonSituations":"Swapping the target object behind a proxy to an instance whose class does not declare the method. Modifying the arguments array length or types inside an advice. Generic/bridge method edge cases where the resolved Method belongs to a superclass/interface. Misconfigured interceptor that passes a Method from the wrong class.","solutions":["Ensure the Method passed to the invocation belongs to the actual target object's class (use AopUtils.getMostSpecificMethod / BridgeMethodResolver).","Do not alter the argument array's length or element types inside advice; if you replace args, keep them type-compatible.","Verify the target bean set on the ProxyFactory/TargetSource is the correct instance type.","Check for bridge-method resolution issues by logging method + target class to spot a class mismatch."],"exampleFix":"// before\n// target swapped to an incompatible instance\nproxyFactory.setTarget(new SomeOtherService());\nmethod.invoke(wrongTarget, args); // -> AOP config invalid\n\n// after\nproxyFactory.setTarget(realServiceInstance);\nMethod m = AopUtils.getMostSpecificMethod(method, realServiceInstance.getClass());\nm.invoke(realServiceInstance, args);","handlingStrategy":"try-catch","validationCode":"if (!method.getDeclaringClass().isInstance(target)\n        && !method.getDeclaringClass().isAssignableFrom(target.getClass())) {\n    // method does not match target class; resolve via getMostSpecificMethod\n}","typeGuard":null,"tryCatchPattern":"try {\n    return AopUtils.invokeJoinpointUsingReflection(target, method, args);\n} catch (AopInvocationException e) {\n    // re-resolve method against the real target class and retry once\n    Method resolved = AopUtils.getMostSpecificMethod(method, target.getClass());\n    return AopUtils.invokeJoinpointUsingReflection(target, resolved, args);\n}","preventionTips":["Always resolve the method against the actual target class before reflection invocation.","Do not mutate the argument array length or incompatible types inside advice.","Keep the target object consistent with the method's declaring class."],"tags":["spring-aop","reflection","invocation","bridge-method"],"backgroundTag":null,"analyzedSha":"69bf83ad716d0cfc4b0520a19b4d8b24c79d1538","analyzedAt":"2026-08-09T15:32:58.770Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}