{"record":{"id":"44aa5c9e3cd51b85","repo":"apache/shenyu","slug":"the-method-cannot-be-called-please-check-the-annotation-and","errorCode":null,"errorMessage":"the method cannot be called, please check the annotation and configuration, method %s","messagePattern":"the method cannot be called, please check the annotation and configuration, method (.+?)","errorType":"exception","errorClass":"ShenyuException","httpStatus":null,"severity":"error","filePath":"shenyu-sdk/shenyu-sdk-spring/src/main/java/org/apache/shenyu/sdk/spring/proxy/ShenyuClientInvocationHandler.java","lineNumber":81,"sourceCode":"    private final FallbackFactory<?> fallbackFactory;\n\n    public ShenyuClientInvocationHandler(final Class<?> apiClass, final ApplicationContext applicationContext,\n                                         final ShenyuClientFactoryBean shenyuClientFactoryBean) {\n        this.shenyuClientFactoryBean = shenyuClientFactoryBean;\n        this.applicationContext = applicationContext;\n        this.contract = applicationContext.getBean(Contract.class);\n        ShenyuClient shenyuClient = apiClass.getAnnotation(ShenyuClient.class);\n        fallbackFactory = getFallbackFactory(shenyuClientFactoryBean.getFallback(),\n                shenyuClientFactoryBean.getFallbackFactory());\n        buildMethodHandlerMap(apiClass, shenyuClient);\n    }\n\n    @Override\n    public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {\n\n        ShenyuClientMethodHandler handler = methodHandlerMap.get(method);\n        if (ObjectUtils.isEmpty(handler)) {\n            throw new ShenyuException(String.format(\"the method cannot be called, please check the annotation and configuration, method %s\", method.getName()));\n        }\n        Object result;\n        try {\n            result = handler.invoke(args);\n        } catch (Throwable throwable) {\n            LOG.error(\"ShenYu Client invoke error  \", throwable);\n            if (Objects.isNull(fallbackFactory)) {\n                throw new NoFallbackAvailableException(\"No fallback available.\", throwable);\n            }\n            Object fallback = fallbackFactory.create(throwable);\n            result = method.invoke(fallback, args);\n        }\n        return result;\n    }\n\n    private void buildMethodHandlerMap(final Class<?> apiClass, final ShenyuClient shenyuClient) {\n        // parseAndValidate RequestTemplate\n        final List<RequestTemplate> requestTemplates = contract.parseAndValidateRequestTemplate(apiClass, shenyuClientFactoryBean);","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/apache/shenyu/blob/567142e07261b3e615ae8850b30f4421f455cc5d/shenyu-sdk/shenyu-sdk-spring/src/main/java/org/apache/shenyu/sdk/spring/proxy/ShenyuClientInvocationHandler.java#L63-L99","documentation":"ShenyuClientInvocationHandler.invoke() dispatches proxied interface methods through a prebuilt methodHandlerMap. Only methods that carry a recognized Shenyu HTTP annotation get a handler; anything else (Object methods or un-annotated methods) has no mapping and throws ShenyuException. It signals an API-definition problem: the proxy was asked to execute a method it was never configured to call.","triggerScenarios":"Calling a method on a @ShenyuClient interface that lacks an HTTP mapping annotation (@Get/@Post/...), or invoking toString/hashCode/equals on the proxy expecting them to be routed.","commonSituations":"Adding a new interface method and forgetting the mapping annotation; annotation on the implementation class instead of the interface; wrong import of the mapping annotation so the scanner ignores it; calling default methods through the proxy.","solutions":["Annotate the called method with a supported HTTP mapping annotation matching its role (@Get, @Post, ...).","Verify the annotation import is the Shenyu SDK one, not a look-alike from another library.","Ensure the annotation is on the interface method the proxy is built from, not only on an implementation.","For non-HTTP helper methods, make them default methods with local logic, or move them out of the client interface."],"exampleFix":"// before\npublic interface OrderApi {\n    OrderDTO getById(Long id);\n}\n// after\npublic interface OrderApi {\n    @Get(\"/order/detail\")\n    OrderDTO getById(@RequestParam(\"id\") Long id);\n}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"static boolean isMappedClientMethod(Method m) {\n    return m.getDeclaringClass() != Object.class\n        && (m.isAnnotationPresent(Get.class) || m.isAnnotationPresent(Post.class)\n            || m.isAnnotationPresent(Put.class) || m.isAnnotationPresent(Delete.class));\n}","tryCatchPattern":null,"preventionTips":["Annotate every method on @ShenyuClient interfaces with a mapping annotation.","Import mapping annotations only from the Shenyu SDK packages.","Keep helper logic in default methods or separate utility classes, not bare interface methods.","Write a package-scan test asserting every client interface method is annotated."],"tags":["proxy","annotation","programming-error"],"backgroundTag":"unsupported-operation","analyzedSha":"567142e07261b3e615ae8850b30f4421f455cc5d","analyzedAt":"2026-09-12T10:08:21.293Z","contentChangedAt":"2026-09-12T10:08:21.293Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}