{"record":{"id":"6e61a44e006cc154","repo":"alibaba/spring-ai-alibaba","slug":"name-6e61a4","errorCode":null,"errorMessage":"重复的模型 name: ","messagePattern":"重复的模型 name: ","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/repository/impl/FileModelConfigRepository.java","lineNumber":135,"sourceCode":"        }\n        if (m.name == null || m.name.isBlank()) {\n            throw new IllegalArgumentException(\"模型缺少 name\");\n        }\n        if (m.provider == null || m.provider.isBlank()) {\n            throw new IllegalArgumentException(\"模型缺少 provider\");\n        }\n        if (m.modelName == null || m.modelName.isBlank()) {\n            throw new IllegalArgumentException(\"模型缺少 modelName\");\n        }\n        //        if (m.baseUrl == null || m.baseUrl.isBlank()) throw new IllegalArgumentException(\"模型缺少 baseUrl\");\n        if (m.apiKey == null || m.apiKey.isBlank()) {\n            throw new IllegalArgumentException(\"模型缺少 apiKey\");\n        }\n        if (!ids.add(m.id)) {\n            throw new IllegalArgumentException(\"重复的模型 id: \" + m.id);\n        }\n        if (!names.add(m.name)) {\n            throw new IllegalArgumentException(\"重复的模型 name: \" + m.name);\n        }\n        if (m.status == null) {\n            m.status = 1;\n        }\n    }\n    \n    private ModelConfigDO toEntity(YamlModel m) {\n        ModelConfigDO.ModelConfigDOBuilder b = ModelConfigDO.builder().id(m.id).name(m.name)\n                .provider(m.provider.toLowerCase()).modelName(m.modelName).baseUrl(m.baseUrl)\n                .apiKey(environment != null ? environment.resolvePlaceholders(m.apiKey) : m.apiKey).status(m.status)\n                .createTime(LocalDateTime.now()).updateTime(LocalDateTime.now());\n        \n        if (m.defaultParameters != null) {\n            try {\n                b.defaultParameters(new ObjectMapper().writeValueAsString(m.defaultParameters));\n            } catch (Exception e) {\n                throw new IllegalArgumentException(\"序列化 defaultParameters 失败\", e);\n            }","sourceCodeStart":117,"sourceCodeEnd":153,"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/repository/impl/FileModelConfigRepository.java#L117-L153","documentation":"validateYamlModel enforces that every model entry has a unique display name via a names Set; when Set.add(m.name) returns false, this IllegalArgumentException is thrown and file loading aborts. Names are used as human-facing identifiers, so duplicates are rejected like duplicate ids.","triggerScenarios":"Calling loadFromFile when two or more model entries in the YAML file have the same (non-null) name field.","commonSituations":"Duplicating a model block to change only the model/parameters but forgetting the name; adding the same logical model twice (e.g., once per deployment); merging team config files with overlapping names.","solutions":["Open the models YAML and make the name field unique for each entry","Locate the duplicate name printed in the message and rename one entry","If the same model must appear twice, suffix the names (e.g., qwen-max, qwen-max-backup)","Re-trigger the file reload / restart the repository watcher after the fix"],"exampleFix":"// before (models.yml)\nmodels:\n  - id: 1\n    name: my-model\n  - id: 2\n    name: my-model\n// after\nmodels:\n  - id: 1\n    name: my-model\n  - id: 2\n    name: my-model-v2","handlingStrategy":"validation","validationCode":"// Java: pre-validate names before writing the YAML\nSet<String> seen = new HashSet<>();\nfor (var m : models) {\n    if (!seen.add(m.getName())) {\n        throw new IllegalStateException(\"Duplicate model name in config: \" + m.getName());\n    }\n}","typeGuard":"boolean isUniqueName(m, Set<String> seen) { return m != null && m.getName() != null && seen.add(m.getName()); }","tryCatchPattern":"try {\n    repository.loadFromFile(path);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().startsWith(\"重复的模型 name\")) {\n        log.error(\"Fix duplicate model name in {}: {}\", path, e.getMessage());\n    }\n}","preventionTips":["Adopt a naming convention (e.g., include variant/env suffix) to prevent collisions","Lint the models YAML for duplicate names in CI","When duplicating an entry, rename it immediately before saving"],"tags":["configuration","duplicate","yaml","unique-constraint"],"backgroundTag":"invalid-config-value","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"}