{"record":{"id":"3fa1457203bd0cba","repo":"spring-projects/spring-framework","slug":"could-not-access-method-method","errorCode":null,"errorMessage":"Could not access method [{method}]","messagePattern":"Could not access method \\[(.+?)\\]","errorType":"exception","errorClass":"AopInvocationException","httpStatus":null,"severity":"error","filePath":"spring-aop/src/main/java/org/springframework/aop/support/AopUtils.java","lineNumber":371,"sourceCode":"\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);\n\t\t}\n\t}\n\n}","sourceCodeStart":353,"sourceCodeEnd":389,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/69bf83ad716d0cfc4b0520a19b4d8b24c79d1538/spring-aop/src/main/java/org/springframework/aop/support/AopUtils.java#L353-L389","documentation":"Thrown by AopUtils.invokeJoinpointUsingReflection (line 370-372) when Method.invoke fails with IllegalAccessException or InaccessibleObjectException after ReflectionUtils.makeAccessible was attempted. The method could not be made accessible - classically due to Java Platform Module System strong encapsulation (a type in a non-exported package) or a SecurityManager/deny policy blocking reflective access. The original exception is wrapped in an AopInvocationException.","triggerScenarios":"Advising a method on a class in a module whose package is not 'opens' to the application, on Java 16+ where strong encapsulation is enforced by default and makeAccessible is denied. Also when a custom SecurityManager forbids suppressAccessChecks, or the method's class loader is isolated.","commonSituations":"Java 16+ modules: an advised bean lives in a library module that does not 'opens' its package to Spring. Accessing JDK internal classes via AOP. Running with a SecurityManager that denies ReflectPermission('suppressAccessChecks'). Upgrading from Java 8/11 to 17 where illegal reflective access is blocked outright.","solutions":["If the class is in your own module, add 'opens your.package to spring.core spring.aop;' (or 'opens ... to ALL-UNNAMED') in module-info.","On the command line, add '--add-opens your.module/your.package=ALL-UNNAMED' to allow reflective access.","Make the method/package-accessible (public, or in an exported/open package) so no suppression is required.","If a SecurityManager is present, grant ReflectPermission 'suppressAccessChecks' to the application codebase."],"exampleFix":"// before (Java 17, advised bean in unopened module)\nmodule my.app { exports com.example; } // not opened\n// -> IllegalAccessException on makeAccessible\n\n// after\nmodule my.app {\n    exports com.example;\n    opens com.example to spring.aop; // or ALL-UNNAMED\n}","handlingStrategy":"validation","validationCode":"try {\n    ReflectionUtils.makeAccessible(method);\n} catch (InaccessibleObjectException e) {\n    // package not opened; instruct user to add --add-opens / 'opens' directive\n}","typeGuard":null,"tryCatchPattern":"try {\n    return method.invoke(target, args);\n} catch (IllegalAccessException | InaccessibleObjectException e) {\n    // surface a clear message about JPMS 'opens' / module access\n    throw new IllegalStateException(\n        \"Method \" + method + \" is inaccessible; open its package to the application module\", e);\n}","preventionTips":["On Java 9+, add 'opens package to spring.aop;' (or ALL-UNNAMED) in module-info.","Use --add-opens JVM args for third-party modules you cannot edit.","Prefer public methods on exported packages for advised beans."],"tags":["spring-aop","reflection","java-modules","jpms","security"],"backgroundTag":null,"analyzedSha":"69bf83ad716d0cfc4b0520a19b4d8b24c79d1538","analyzedAt":"2026-08-09T15:32:58.770Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}