{"record":{"id":"a89d7b18495a8043","repo":"alibaba/spring-ai-alibaba","slug":"error-a89d7b","errorCode":null,"errorMessage":"模型配置不能为空","messagePattern":"模型配置不能为空","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":38,"sourceCode":"@Component\n@RequiredArgsConstructor\npublic class ModelConfigParser {\n    \n    private final ObjectMapper objectMapper;\n    \n    private final ModelConfigRepository modelConfigRepository;\n    \n    private final ModelManager modelManager;\n    \n    /**\n     * 解析模型配置JSON字符串\n     *\n     * @param modelConfigJson 模型配置JSON\n     * @return 模型配置信息\n     */\n    public ModelConfigInfo parseModelConfig(String modelConfigJson) {\n        if (!StringUtils.hasText(modelConfigJson)) {\n            throw new IllegalArgumentException(\"模型配置不能为空\");\n        }\n        \n        try {\n            return objectMapper.readValue(modelConfigJson, ModelConfigInfo.class);\n        } catch (Exception e) {\n            log.error(\"解析模型配置JSON失败: {}\", modelConfigJson, e);\n            throw new IllegalArgumentException(\"模型配置格式错误: \" + e.getMessage(), e);\n        }\n    }\n    \n    public ModelConfigInfo checkAndGetModelConfigInfo(String modelConfig) {\n        ModelConfigInfo modelConfigInfo = null;\n        try {\n            modelConfigInfo = parseModelConfig(modelConfig);\n            validateModelConfig(modelConfigInfo);\n            \n            // 验证模型配置是否存在\n            // 首先尝试从 ModelConfigRepository (YAML 文件) 查找","sourceCodeStart":20,"sourceCodeEnd":56,"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#L20-L56","documentation":"An IllegalArgumentException thrown by ModelConfigParser.parseModelConfig when the modelConfigJson argument is null, empty, or blank (StringUtils.hasText fails). The parser requires a non-empty JSON string describing the model configuration before it attempts deserialization.","triggerScenarios":"Calling parseModelConfig(modelConfigJson) with null/empty/whitespace string — typically when the persisted prompt or agent record has no modelConfig column value, or the caller passes an unset variable.","commonSituations":"Legacy rows created before modelConfig was mandatory; prompts created via a UI path that skipped model selection; a migration that left the column NULL; passing request.getModelConfig() without null-checking.","solutions":["Ensure the caller supplies a valid modelConfig JSON before invoking the parser (null-check and reject early).","Backfill missing model_config values in the database for affected records.","Wrap the call in checkAndGetModelConfigInfo or your own guard that skips/default-handles empty configs.","Return a clear validation error to the upstream request instead of letting it reach the parser."],"exampleFix":"// before\nModelConfigInfo info = parser.parseModelConfig(request.getModelConfig()); // NPE risk / IAE if empty\n// after\nif (StringUtils.hasText(request.getModelConfig())) {\n    ModelConfigInfo info = parser.parseModelConfig(request.getModelConfig());\n}","handlingStrategy":"validation","validationCode":"if (modelConfigJson == null || modelConfigJson.isBlank()) throw new BadRequestException(\"modelConfig is required\");","typeGuard":"boolean hasModelConfig = modelConfigJson != null && !modelConfigJson.isBlank();","tryCatchPattern":"try { return parser.parseModelConfig(cfg); } catch (IllegalArgumentException e) { if (!StringUtils.hasText(cfg)) return defaultConfig(); throw e; }","preventionTips":["Make modelConfig a required field at the API/DB level","Null-check config values pulled from optional request fields","Backfill or reject legacy rows with NULL model_config"],"tags":["validation","model-config","illegal-argument"],"backgroundTag":"empty-required-field","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}