{"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/e8729d043887bf0d0baf91e062e909b56eb2b708/spring-aop/src/main/java/org/springframework/aop/support/AopUtils.java#L353-L389","documentation":"invokeJoinpointUsingReflection catches IllegalAccessException and InaccessibleObjectException from Method.invoke (even after ReflectionUtils.makeAccessible) and wraps them as AopInvocationException 'Could not access method'. The JVM refused the reflective call, most often because the Java Platform Module System (JPMS) blocks access to a class in another module.","triggerScenarios":"Reflectively invoking a non-opened package member (e.g. a JDK internal class, or a class in another module) without the corresponding --add-opens, or a method whose declaring class is inaccessible to the caller module.","commonSituations":"JDK 9+ strong encapsulation blocking reflective access to java.base internals; advising code that touches JDK internals; sealed library classes; Kotlin/Scala compiler-generated classes with restrictive visibility.","solutions":["Add the appropriate --add-opens=module/package=ALL-UNNAMED JVM argument for the offending package.","Make the target method public or package-private so makeAccessible succeeds.","Avoid advising/reflecting into JDK-internal classes; use supported APIs instead."],"exampleFix":"# before\njava -jar app.jar\n# -> Could not access method [java.base/java.lang.X.y] (InaccessibleObjectException)\n\n# after\njava --add-opens=java.base/java.lang=ALL-UNNAMED -jar app.jar","handlingStrategy":"validation","validationCode":"try {\n    method.setAccessible(true); // fails fast under JPMS if not open\n} catch (InaccessibleObjectException ex) {\n    // require --add-opens for method's declaring package\n}","typeGuard":"boolean isAccessibleInModule(java.lang.reflect.Method m) {\n    try { m.setAccessible(true); return true; }\n    catch (InaccessibleObjectException e) { return false; }\n}","tryCatchPattern":"try {\n    return AopUtils.invokeJoinpointUsingReflection(target, method, args);\n} catch (AopInvocationException ex) {\n    if (ex.getCause() instanceof InaccessibleObjectException) {\n        // add --add-opens or widen visibility\n    }\n    throw ex;\n}","preventionTips":["Run with --add-opens for any non-opened packages you must reflect into.","Prefer public methods for advised joinpoints.","Avoid advising JDK-internal classes."],"tags":["spring-aop","reflection","jpms","modules","accessibility"],"analyzedSha":"e8729d043887bf0d0baf91e062e909b56eb2b708","analyzedAt":"2026-08-04T19:07:39.725Z","schemaVersion":2}