spring-projects/spring-ai · error · IllegalArgumentException

clients must not be empty

Error message

clients must not be empty

What it means

SyncLoggingSpecification's compact constructor validates that the clients array is non-null, has at least one element, and contains no empty strings. Violations throw this IllegalArgumentException immediately at construction. It is the sync counterpart of the AsyncLoggingSpecification check, guarding synchronous MCP logging registrations.

Solutions

  1. Supply at least one valid, non-empty client name.
  2. Filter blank entries from the array before construction.
  3. If no specific clients are needed, look for an API variant that accepts no client filter rather than an empty array.
  4. Add a startup assertion on the config value feeding the client list.

Example fix

// before
var spec = new SyncLoggingSpecification(new String[]{}, this::onLog);
// after
var spec = new SyncLoggingSpecification(new String[]{"my-client"}, this::onLog);
Defensive patterns

Strategy: validation

Validate before calling

if (clients == null || clients.length == 0 || Arrays.stream(clients).anyMatch(c -> c == null || c.isEmpty())) {
    throw new IllegalStateException("SyncLoggingSpecification requires at least one non-empty client name");
}

Try / catch

try {
    new SyncLoggingSpecification(clients, consumer);
} catch (IllegalArgumentException e) {
    logger.error("Invalid sync logging clients: {}", e.getMessage());
}

Prevention

When it happens

Trigger: new SyncLoggingSpecification(new String[]{}, consumer), null clients, or an array containing "" passed while registering a sync logging consumer with an MCP server.

Common situations: See trigger scenarios.

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


AI-assisted analysis of spring-projects/spring-ai@98a7beda4f (2026-09-11). Data as JSON: /api/errors/5d2cee6307af66ad. Report an issue: GitHub.

Appendix: source

Thrown at mcp/mcp-annotations/src/main/java/org/springframework/ai/mcp/annotation/method/logging/SyncLoggingSpecification.java:30

 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.ai.mcp.annotation.method.logging;

import java.util.Arrays;
import java.util.Objects;
import java.util.function.Consumer;

import io.modelcontextprotocol.spec.McpSchema.LoggingMessageNotification;

public record SyncLoggingSpecification(String[] clients, Consumer<LoggingMessageNotification> loggingHandler) {

	public SyncLoggingSpecification {
		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)