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

  1. Send the tenant id strictly as a base-10 numeric value (string or number), no quotes/whitespace.
  2. Validate the header at the edge (gateway filter or controller advice) before it reaches the messaging layer.
  3. If tenants must be addressed by code, resolve code->id at the boundary and only propagate the numeric id.
  4. 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

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


AI-assisted analysis of YunaiV/yudao-cloud@477be9dd49 (2026-08-14). Data as JSON: /api/errors/fe64eb8cc089c2cc. Report an issue: GitHub.