alibaba/spring-ai-alibaba · error · IllegalArgumentException
重复的模型 name:
Error message
重复的模型 name:
What it means
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.
Source
Thrown at spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-start/src/main/java/com/alibaba/cloud/ai/studio/admin/repository/impl/FileModelConfigRepository.java:135
}
if (m.name == null || m.name.isBlank()) {
throw new IllegalArgumentException("模型缺少 name");
}
if (m.provider == null || m.provider.isBlank()) {
throw new IllegalArgumentException("模型缺少 provider");
}
if (m.modelName == null || m.modelName.isBlank()) {
throw new IllegalArgumentException("模型缺少 modelName");
}
// if (m.baseUrl == null || m.baseUrl.isBlank()) throw new IllegalArgumentException("模型缺少 baseUrl");
if (m.apiKey == null || m.apiKey.isBlank()) {
throw new IllegalArgumentException("模型缺少 apiKey");
}
if (!ids.add(m.id)) {
throw new IllegalArgumentException("重复的模型 id: " + m.id);
}
if (!names.add(m.name)) {
throw new IllegalArgumentException("重复的模型 name: " + m.name);
}
if (m.status == null) {
m.status = 1;
}
}
private ModelConfigDO toEntity(YamlModel m) {
ModelConfigDO.ModelConfigDOBuilder b = ModelConfigDO.builder().id(m.id).name(m.name)
.provider(m.provider.toLowerCase()).modelName(m.modelName).baseUrl(m.baseUrl)
.apiKey(environment != null ? environment.resolvePlaceholders(m.apiKey) : m.apiKey).status(m.status)
.createTime(LocalDateTime.now()).updateTime(LocalDateTime.now());
if (m.defaultParameters != null) {
try {
b.defaultParameters(new ObjectMapper().writeValueAsString(m.defaultParameters));
} catch (Exception e) {
throw new IllegalArgumentException("序列化 defaultParameters 失败", e);
}View on GitHub (pinned to f82da0b50f)
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
Example fix
// before (models.yml)
models:
- id: 1
name: my-model
- id: 2
name: my-model
// after
models:
- id: 1
name: my-model
- id: 2
name: my-model-v2 Defensive patterns
Strategy: validation
Validate before calling
// Java: pre-validate names before writing the YAML
Set<String> seen = new HashSet<>();
for (var m : models) {
if (!seen.add(m.getName())) {
throw new IllegalStateException("Duplicate model name in config: " + m.getName());
}
} Type guard
boolean isUniqueName(m, Set<String> seen) { return m != null && m.getName() != null && seen.add(m.getName()); } Try / catch
try {
repository.loadFromFile(path);
} catch (IllegalArgumentException e) {
if (e.getMessage().startsWith("重复的模型 name")) {
log.error("Fix duplicate model name in {}: {}", path, e.getMessage());
}
} Prevention
- 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
When it happens
Trigger: Calling loadFromFile when two or more model entries in the YAML file have the same (non-null) name field.
Common situations: 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.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09).
Data as JSON: /api/errors/6e61a44e006cc154.
Report an issue: GitHub.