{"record":{"id":"9eb08cb23c09c844","repo":"alibaba/spring-ai-alibaba","slug":"id-9eb08c","errorCode":null,"errorMessage":"模型ID不能为空","messagePattern":"模型ID不能为空","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-start/src/main/java/com/alibaba/cloud/ai/studio/admin/utils/ModelConfigParser.java","lineNumber":194,"sourceCode":"        } catch (Exception e) {\n            log.warn(\"变量替换失败，使用原始模板: template={}, variables={}\", template, variablesJson, e);\n            return template;\n        }\n    }\n    \n    /**\n     * 验证模型配置的有效性 只验证必需字段，动态参数由模型服务自行验证\n     *\n     * @param modelConfigInfo 模型配置信息\n     * @throws IllegalArgumentException 如果配置无效\n     */\n    public void validateModelConfig(ModelConfigInfo modelConfigInfo) {\n        if (modelConfigInfo == null) {\n            throw new IllegalArgumentException(\"模型配置不能为空\");\n        }\n        \n        if (modelConfigInfo.getModelId() == null) {\n            throw new IllegalArgumentException(\"模型ID不能为空\");\n        }\n        \n        // 只进行基本的数据类型验证，具体的参数范围由模型服务验证\n        validateParameterTypes(modelConfigInfo);\n    }\n    \n    /**\n     * 验证参数类型是否合理 确保数值参数确实是数值类型\n     *\n     * @param modelConfigInfo 模型配置信息\n     */\n    private void validateParameterTypes(ModelConfigInfo modelConfigInfo) {\n        Map<String, Object> parameters = modelConfigInfo.getAllParameters();\n        \n        for (Map.Entry<String, Object> entry : parameters.entrySet()) {\n            String name = entry.getKey();\n            Object value = entry.getValue();\n            ","sourceCodeStart":176,"sourceCodeEnd":212,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-start/src/main/java/com/alibaba/cloud/ai/studio/admin/utils/ModelConfigParser.java#L176-L212","documentation":"An IllegalArgumentException thrown by ModelConfigParser.validateModelConfig when ModelConfigInfo is non-null but its modelId field is null. A model configuration must identify which model to use; without modelId it cannot be resolved or executed.","triggerScenarios":"Calling validateModelConfig with a ModelConfigInfo deserialized from JSON lacking a 'modelId' key, or one built programmatically without setModelId(...). Note checkAndGetModelConfigInfo may later overwrite modelId with the ModelEntity id — but validation before that will still fail.","commonSituations":"Hand-written config JSON missing the modelId field; renamed field (e.g. 'model' vs 'modelId') so Jackson leaves modelId null; constructing ModelConfigInfo in tests/other code without setting the id.","solutions":["Add the modelId field to the config JSON (e.g. {\"modelId\":\"qwen-max\",...}).","Set modelConfigInfo.setModelId(...) before validation when building the object in code.","Check field naming against ModelConfigInfo so Jackson actually populates modelId (watch @JsonProperty aliases).","Run parser.parseModelConfig on the JSON and log the resulting modelId to confirm deserialization."],"exampleFix":"// before\nString cfg = \"{\\\"modelName\\\":\\\"qwen-max\\\"}\"; // no modelId\nModelConfigInfo info = parser.parseModelConfig(cfg);\nparser.validateModelConfig(info); // IAE: 模型ID不能为空\n// after\nString cfg = \"{\\\"modelId\\\":\\\"qwen-max\\\"}\";\nModelConfigInfo info = parser.parseModelConfig(cfg);\nparser.validateModelConfig(info); // ok","handlingStrategy":"validation","validationCode":"if (info.getModelId() == null || info.getModelId().isBlank()) throw new BadRequestException(\"modelId is required in model config\");","typeGuard":"boolean hasModelId = modelConfigInfo != null && modelConfigInfo.getModelId() != null;","tryCatchPattern":"try { parser.validateModelConfig(info); } catch (IllegalArgumentException e) { if (e.getMessage().contains(\"模型ID不能为空\")) { /* fix config JSON to include modelId */ } throw e; }","preventionTips":["Always include modelId in stored config JSON","Verify Jackson field mapping matches ModelConfigInfo property names","Assert modelId after parsing in tests for config fixtures"],"tags":["validation","model-config","missing-field"],"backgroundTag":"missing-required-config-field","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}