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

  1. Change the handler's return type to the required type: String for urlCleaner, ClientHttpResponse for block/fallback.
  2. If returning a custom response, wrap it so it implements ClientHttpResponse.
  3. 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

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


AI-assisted analysis of alibaba/spring-cloud-alibaba@115d590110 (2026-08-14). Data as JSON: /api/errors/b3f5bd85a0d7408d. Report an issue: GitHub.