{"record":{"id":"5d2cee6307af66ad","repo":"spring-projects/spring-ai","slug":"clients-must-not-be-empty-5d2cee","errorCode":null,"errorMessage":"clients must not be empty","messagePattern":"clients must not be empty","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"mcp/mcp-annotations/src/main/java/org/springframework/ai/mcp/annotation/method/logging/SyncLoggingSpecification.java","lineNumber":30,"sourceCode":" * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage org.springframework.ai.mcp.annotation.method.logging;\n\nimport java.util.Arrays;\nimport java.util.Objects;\nimport java.util.function.Consumer;\n\nimport io.modelcontextprotocol.spec.McpSchema.LoggingMessageNotification;\n\npublic record SyncLoggingSpecification(String[] clients, Consumer<LoggingMessageNotification> loggingHandler) {\n\n\tpublic SyncLoggingSpecification {\n\t\tObjects.requireNonNull(clients, \"clients must not be null\");\n\t\tif (clients.length == 0 || Arrays.stream(clients).anyMatch(String::isEmpty)) {\n\t\t\tthrow new IllegalArgumentException(\"clients must not be empty\");\n\t\t}\n\t\tObjects.requireNonNull(loggingHandler, \"loggingHandler must not be null\");\n\t}\n}\n","sourceCodeStart":12,"sourceCodeEnd":35,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/mcp/mcp-annotations/src/main/java/org/springframework/ai/mcp/annotation/method/logging/SyncLoggingSpecification.java#L12-L35","documentation":"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.","triggerScenarios":"new SyncLoggingSpecification(new String[]{}, consumer), null clients, or an array containing \"\" passed while registering a sync logging consumer with an MCP server.","commonSituations":"See trigger scenarios.","solutions":["Supply at least one valid, non-empty client name.","Filter blank entries from the array before construction.","If no specific clients are needed, look for an API variant that accepts no client filter rather than an empty array.","Add a startup assertion on the config value feeding the client list."],"exampleFix":"// before\nvar spec = new SyncLoggingSpecification(new String[]{}, this::onLog);\n// after\nvar spec = new SyncLoggingSpecification(new String[]{\"my-client\"}, this::onLog);","handlingStrategy":"validation","validationCode":"if (clients == null || clients.length == 0 || Arrays.stream(clients).anyMatch(c -> c == null || c.isEmpty())) {\n    throw new IllegalStateException(\"SyncLoggingSpecification requires at least one non-empty client name\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    new SyncLoggingSpecification(clients, consumer);\n} catch (IllegalArgumentException e) {\n    logger.error(\"Invalid sync logging clients: {}\", e.getMessage());\n}","preventionTips":["Filter blank entries from split() results before constructing","Never assume empty array means 'all clients'","Validate the config source at startup"],"tags":["mcp","validation","constructor","java"],"backgroundTag":"empty-required-field","analyzedSha":"98a7beda4f29d80a71c5837eb4053b03a93a46f7","analyzedAt":"2026-09-11T14:15:49.441Z","contentChangedAt":"2026-09-11T14:15:49.441Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}