alibaba/spring-cloud-alibaba · error · IllegalArgumentException
{type} method return value in bean[{beanName}] is not {stand
Error message
{type} method return value in bean[{beanName}] is not {standardReturnType}: {blockClass}#{blockMethod}{argsStr} What it means
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.
Source
Thrown at spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/custom/SentinelBeanPostProcessor.java:161
+ " static method can not be found in bean[" + beanName
+ "]. The right method signature is " + blockClass.getName() + "#"
+ blockMethod + argsStr
+ ", please check your class name, method name and arguments");
}
Class<?> standardReturnType;
if (type.equals(SentinelConstants.URLCLEANER_TYPE)) {
standardReturnType = String.class;
}
else {
standardReturnType = ClientHttpResponse.class;
}
if (!standardReturnType.isAssignableFrom(foundMethod.getReturnType())) {
log.error("{} method return value in bean[{}] is not {}: {}#{}{}", type,
beanName, standardReturnType.getName(), blockClass.getName(),
blockMethod, argsStr);
throw new IllegalArgumentException(type + " method return value in bean["
+ beanName + "] is not " + standardReturnType.getName() + ": "
+ blockClass.getName() + "#" + blockMethod + argsStr);
}
if (type.equals(SentinelConstants.BLOCK_TYPE)) {
BlockClassRegistry.updateBlockHandlerFor(blockClass, blockMethod,
foundMethod);
}
else if (type.equals(SentinelConstants.FALLBACK_TYPE)) {
BlockClassRegistry.updateFallbackFor(blockClass, blockMethod, foundMethod);
}
else {
BlockClassRegistry.updateUrlCleanerFor(blockClass, blockMethod, foundMethod);
}
}
@Override
public Object postProcessAfterInitialization(Object bean, String beanName)
throws BeansException {View on GitHub (pinned to 115d590110)
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.
Example fix
// before
public static Object clean(String url) { return url; }
// after
public static String clean(String url) { return url; } Defensive patterns
Strategy: validation
Validate before calling
void requireReturnType(Class<?> expected, Class<?> c, String name, Class<?>... args) throws NoSuchMethodException {
Class<?> rt = c.getMethod(name, args).getReturnType();
if (!expected.isAssignableFrom(rt)) throw new IllegalStateException(name + " must return " + expected.getName());
} Type guard
static boolean returnsType(Class<?> expected, Class<?> c, String name, Class<?>... args) {
try { return expected.isAssignableFrom(c.getMethod(name, args).getReturnType()); }
catch (NoSuchMethodException e) { return false; }
} Prevention
- Return String for urlCleaner, ClientHttpResponse for block/fallback.
- Add a compile-time test asserting the return type.
- Re-check after refactoring handler methods.
When it happens
Trigger: A block handler declared to return ResponseEntity or void instead of ClientHttpResponse; a urlCleaner returning Object or URL instead of String.
Common situations: 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.
Related errors
- {type} static method can not be found in bean[{beanName}]. T
- {type} class attribute exists but {type} method attribute is
- {type} method attribute exists but {type} class attribute is
- [Sentinel Starter] DataSource {dataSourceName} field: {field
- NacosConfigKeysChangeListener must be marked as a single par
AI-assisted analysis of alibaba/spring-cloud-alibaba@115d590110 (2026-08-14).
Data as JSON: /api/errors/b3f5bd85a0d7408d.
Report an issue: GitHub.