spring-projects/spring-ai · error · IllegalArgumentException
clients must not be empty
Error message
clients must not be empty
What it means
The AsyncLoggingSpecification record is a compact-constructor validation for an async MCP logging registration. The clients array must be non-null, non-empty, and contain no empty strings; otherwise an IllegalArgumentException is thrown at construction time. This fails fast so invalid logging registrations are caught before they are wired into an MCP server.
Solutions
- Pass at least one non-empty client name in the clients array.
- If logging should apply to all clients, check the library API for a wildcard or null/absent-clients overload instead of passing an empty array.
- Filter out blank entries before constructing: Arrays.stream(raw).filter(s -> s != null && !s.isBlank()).toArray(String[]::new).
- Validate the configuration source (properties/env) actually populated the client list before calling the constructor.
Example fix
// before
var spec = new AsyncLoggingSpecification(config.getLoggingClients().split(","), handler);
// after
String[] clients = config.getLoggingClients() == null || config.getLoggingClients().isBlank()
? new String[]{"default-client"}
: Arrays.stream(config.getLoggingClients().split(","))
.map(String::trim).filter(s -> !s.isEmpty()).toArray(String[]::new);
var spec = new AsyncLoggingSpecification(clients, handler); Defensive patterns
Strategy: validation
Validate before calling
String[] clients = /* from config */;
if (clients == null || clients.length == 0 || Arrays.stream(clients).anyMatch(c -> c == null || c.isEmpty())) {
throw new IllegalStateException("AsyncLoggingSpecification requires at least one non-empty client name");
} Try / catch
try {
new AsyncLoggingSpecification(clients, handler);
} catch (IllegalArgumentException e) {
logger.error("Invalid MCP logging clients config: {}", e.getMessage());
} Prevention
- Normalize config lists with trim + filter before constructing specifications
- Fail startup with a clear message if the client list is empty
- Add a unit test covering empty and blank-entry arrays
When it happens
Trigger: Calling new AsyncLoggingSpecification(new String[0], handler), passing null clients, or passing an array containing an empty string (e.g. new String[]{""}) while building an async logging specification for an MCP server.
Common situations: Building client lists dynamically from configuration or environment variables that resolve to an empty array or blank entries; a YAML/properties list that parsed to empty; string-splitting an empty config value producing [""] instead of a zero-length array.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- clients must not be empty
- Bean must not be null
- clients must not be empty
- clients must not be empty
- clients must not be empty
AI-assisted analysis of spring-projects/spring-ai@98a7beda4f (2026-09-11).
Data as JSON: /api/errors/b9b81ee6e9575878.
Report an issue: GitHub.
Appendix: source
Thrown at mcp/mcp-annotations/src/main/java/org/springframework/ai/mcp/annotation/method/logging/AsyncLoggingSpecification.java:32
* limitations under the License.
*/
package org.springframework.ai.mcp.annotation.method.logging;
import java.util.Arrays;
import java.util.Objects;
import java.util.function.Function;
import io.modelcontextprotocol.spec.McpSchema.LoggingMessageNotification;
import reactor.core.publisher.Mono;
public record AsyncLoggingSpecification(String[] clients,
Function<LoggingMessageNotification, Mono<Void>> loggingHandler) {
public AsyncLoggingSpecification {
Objects.requireNonNull(clients, "clients must not be null");
if (clients.length == 0 || Arrays.stream(clients).anyMatch(String::isEmpty)) {
throw new IllegalArgumentException("clients must not be empty");
}
Objects.requireNonNull(loggingHandler, "loggingHandler must not be null");
}
}
View on GitHub (pinned to 98a7beda4f)