{"record":{"id":"b3f5bd85a0d7408d","repo":"alibaba/spring-cloud-alibaba","slug":"type-method-return-value-in-bean-beanname-is","errorCode":null,"errorMessage":"{type} method return value in bean[{beanName}] is not {standardReturnType}: {blockClass}#{blockMethod}{argsStr}","messagePattern":"(.+?) method return value in bean\\[(.+?)\\] is not (.+?): (.+?)#(.+?)(.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/custom/SentinelBeanPostProcessor.java","lineNumber":161,"sourceCode":"\t\t\t\t\t+ \" static method can not be found in bean[\" + beanName\n\t\t\t\t\t+ \"]. The right method signature is \" + blockClass.getName() + \"#\"\n\t\t\t\t\t+ blockMethod + argsStr\n\t\t\t\t\t+ \", please check your class name, method name and arguments\");\n\t\t}\n\n\t\tClass<?> standardReturnType;\n\t\tif (type.equals(SentinelConstants.URLCLEANER_TYPE)) {\n\t\t\tstandardReturnType = String.class;\n\t\t}\n\t\telse {\n\t\t\tstandardReturnType = ClientHttpResponse.class;\n\t\t}\n\n\t\tif (!standardReturnType.isAssignableFrom(foundMethod.getReturnType())) {\n\t\t\tlog.error(\"{} method return value in bean[{}] is not {}: {}#{}{}\", type,\n\t\t\t\t\tbeanName, standardReturnType.getName(), blockClass.getName(),\n\t\t\t\t\tblockMethod, argsStr);\n\t\t\tthrow new IllegalArgumentException(type + \" method return value in bean[\"\n\t\t\t\t\t+ beanName + \"] is not \" + standardReturnType.getName() + \": \"\n\t\t\t\t\t+ blockClass.getName() + \"#\" + blockMethod + argsStr);\n\t\t}\n\t\tif (type.equals(SentinelConstants.BLOCK_TYPE)) {\n\t\t\tBlockClassRegistry.updateBlockHandlerFor(blockClass, blockMethod,\n\t\t\t\t\tfoundMethod);\n\t\t}\n\t\telse if (type.equals(SentinelConstants.FALLBACK_TYPE)) {\n\t\t\tBlockClassRegistry.updateFallbackFor(blockClass, blockMethod, foundMethod);\n\t\t}\n\t\telse {\n\t\t\tBlockClassRegistry.updateUrlCleanerFor(blockClass, blockMethod, foundMethod);\n\t\t}\n\t}\n\n\t@Override\n\tpublic Object postProcessAfterInitialization(Object bean, String beanName)\n\t\t\tthrows BeansException {","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/alibaba/spring-cloud-alibaba/blob/115d5901102009492e05d5ec18c3f79cad4077d0/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/custom/SentinelBeanPostProcessor.java#L143-L179","documentation":"Once a matching static method is found, Sentinel checks its return type with isAssignableFrom. A urlCleaner handler must return String; a block/fallback handler must return ClientHttpResponse. If the method returns an incompatible type, this IllegalArgumentException is raised at startup, naming the offending class#method and the expected return type.","triggerScenarios":"A block handler declared to return ResponseEntity or void instead of ClientHttpResponse; a urlCleaner returning Object or URL instead of String.","commonSituations":"Adapting a controller method into a Sentinel handler and forgetting to change the return type. Returning a wrapper type that is not assignable to the required interface.","solutions":["Change the handler's return type to the required type: String for urlCleaner, ClientHttpResponse for block/fallback.","If returning a custom response, wrap it so it implements ClientHttpResponse.","Recompile and restart so the post-processor sees the corrected signature."],"exampleFix":"// before\npublic static Object clean(String url) { return url; }\n// after\npublic static String clean(String url) { return url; }","handlingStrategy":"validation","validationCode":"void requireReturnType(Class<?> expected, Class<?> c, String name, Class<?>... args) throws NoSuchMethodException {\n  Class<?> rt = c.getMethod(name, args).getReturnType();\n  if (!expected.isAssignableFrom(rt)) throw new IllegalStateException(name + \" must return \" + expected.getName());\n}","typeGuard":"static boolean returnsType(Class<?> expected, Class<?> c, String name, Class<?>... args) {\n  try { return expected.isAssignableFrom(c.getMethod(name, args).getReturnType()); }\n  catch (NoSuchMethodException e) { return false; }\n}","tryCatchPattern":null,"preventionTips":["Return String for urlCleaner, ClientHttpResponse for block/fallback.","Add a compile-time test asserting the return type.","Re-check after refactoring handler methods."],"tags":["sentinel","resttemplate","reflection","return-type"],"backgroundTag":null,"analyzedSha":"115d5901102009492e05d5ec18c3f79cad4077d0","analyzedAt":"2026-08-14T04:47:13.900Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}