YunaiV/yudao-cloud · error · IllegalArgumentException
未知的数据类型:{}
Error message
未知的数据类型:{} What it means
A patched Spring InvocableHandlerMethod converts an incoming message header (the tenant id) to Long. It handles Long, Number, numeric String, and byte[] of digits; any other runtime type (Map, JsonObject, non-numeric String, null-wrapped weirdly) triggers IllegalArgumentException with the value printed.
Source
Thrown at yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/org/springframework/messaging/handler/invocation/InvocableHandlerMethod.java:149
private Long parseTenantId(Message<?> message) {
Object tenantId = message.getHeaders().get(HEADER_TENANT_ID);
if (tenantId == null) {
return null;
}
if (tenantId instanceof Long) {
return (Long) tenantId;
}
if (tenantId instanceof Number) {
return ((Number) tenantId).longValue();
}
if (tenantId instanceof String) {
return Long.parseLong((String) tenantId);
}
if (tenantId instanceof byte[]) {
return Long.parseLong(new String((byte[]) tenantId));
}
throw new IllegalArgumentException("未知的数据类型:" + tenantId);
}
/**
* Get the method argument values for the current message, checking the provided
* argument values and falling back to the configured argument resolvers.
* <p>The resulting array will be passed into {@link #doInvoke}.
* @since 5.1.2
*/
protected Object[] getMethodArgumentValues(Message<?> message, Object... providedArgs) throws Exception {
MethodParameter[] parameters = getMethodParameters();
if (ObjectUtils.isEmpty(parameters)) {
return EMPTY_ARGS;
}
Object[] args = new Object[parameters.length];
for (int i = 0; i < parameters.length; i++) {
MethodParameter parameter = parameters[i];
parameter.initParameterNameDiscovery(this.parameterNameDiscoverer);View on GitHub (pinned to 477be9dd49)
Solutions
- Send the tenant id strictly as a base-10 numeric value (string or number), no quotes/whitespace.
- Validate the header at the edge (gateway filter or controller advice) before it reaches the messaging layer.
- If tenants must be addressed by code, resolve code->id at the boundary and only propagate the numeric id.
- Check the printed value in the message to identify which client/message is malformed.
Example fix
// client before
headers.put("tenant-id", "\"1\""); // quoted -> parse fails
// client after
headers.put("tenant-id", "1"); Defensive patterns
Strategy: validation
Validate before calling
Object raw = message.getHeaders().get("tenant-id");
if (raw instanceof String s && !s.matches("\\d+")) {
throw new IllegalArgumentException("tenant-id must be numeric, got: " + s);
} Type guard
static boolean isConvertibleTenantId(Object v) {
return v instanceof Long || v instanceof Number || v instanceof byte[]
|| (v instanceof String s && s.matches("\\d+"));
} Try / catch
try {
Long tenantId = convertTenant(message.getHeaders().get("tenant-id"));
} catch (IllegalArgumentException | NumberFormatException e) {
rejectMessageWithReason("invalid tenant-id header: " + e.getMessage());
} Prevention
- Validate the tenant-id header format at gateway/edge before messages reach handlers
- Standardize tenant propagation as a plain base-10 numeric string in all clients
When it happens
Trigger: A WebSocket/RabbitMQ/Redis message carries the tenant header as a non-numeric payload — e.g. JSON object {"tenantId": "tenant-a"}, a UUID string, or the tenant propagation header set from user input without validation; Long.parseLong('1abc') inside the String/byte[] branch throws NumberFormatException in the same conversion helper.
Common situations: Frontend sends tenant-id header with whitespace or quotes ('"1"'); a gateway/proxy rewrites the header to a non-numeric tenant code; payload schemas that serialize numbers as JSON strings with units; version drift where a client starts sending tenant 'name' instead of id.
Related errors
- TenantContextHolder 不存在租户编号!可参考文档:https://doc.iocoder.cn
- Cannot convert type {} to a boolean value
- LoginUser(%d) Table(%s/%s) 未返回数据权限
- AreaUtils 初始化失败
- IPUtils 初始化失败
AI-assisted analysis of YunaiV/yudao-cloud@477be9dd49 (2026-08-14).
Data as JSON: /api/errors/fe64eb8cc089c2cc.
Report an issue: GitHub.