alibaba/spring-ai-alibaba · error · IllegalArgumentException
Invalid status:
Error message
Invalid status:
What it means
CommonStatus.of() throws IllegalArgumentException when the given status string matches no CommonStatus enum constant. CommonStatus models generic enabled/disabled-style record states, and of() refuses unrecognized values.
Source
Thrown at spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-runtime/src/main/java/com/alibaba/cloud/ai/studio/runtime/enums/CommonStatus.java:71
/**
* String representation of the status
*/
private final String value;
/**
* Converts a numeric status code to its corresponding enum value
* @param status numeric status code
* @return corresponding CommonStatus enum value
* @throws IllegalArgumentException if the status code is invalid
*/
public static CommonStatus of(Integer status) {
for (CommonStatus commonStatus : CommonStatus.values()) {
if (commonStatus.status.equals(status)) {
return commonStatus;
}
}
throw new IllegalArgumentException("Invalid status: " + status);
}
}
View on GitHub (pinned to f82da0b50f)
Solutions
- Pass exactly one of the value strings defined by CommonStatus.
- Normalize input (trim, case) before calling of().
- Catch IllegalArgumentException at deserialization boundaries and surface a validation error.
- Extend the enum if a genuinely new status is required.
Example fix
// before
CommonStatus st = CommonStatus.of("1"); // throws
// after
CommonStatus st = CommonStatus.of("ENABLED"); // match defined value Defensive patterns
Strategy: validation
Validate before calling
boolean valid = Arrays.stream(CommonStatus.values())
.anyMatch(s -> s.getStatus().equals(candidate)); Type guard
Optional<CommonStatus> tryCommonStatus(String s) {
try { return Optional.of(CommonStatus.of(s)); }
catch (IllegalArgumentException e) { return Optional.empty(); }
} Try / catch
try {
st = CommonStatus.of(raw);
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Unsupported status; use CommonStatus values", e);
} Prevention
- Use the enum constants' value strings, not booleans or numeric codes.
- Normalize case/whitespace on strings from clients or legacy DB columns.
- Serialize with the enum so status strings stay consistent end-to-end.
- Guard of() calls with a validation helper at API boundaries.
When it happens
Trigger: Calling CommonStatus.of(status) with a string that is null, empty, or not among the enum's value strings.
Common situations: Booleans ("true"/"1") passed instead of the expected status strings; numeric status codes from legacy schemas; case mismatches.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- Unknown agent status code:
- Unknown agent type code:
- Invalid MessageType value:
- Invalid status:
- Invalid status:
AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09).
Data as JSON: /api/errors/114e4c7b5c6f9ab0.
Report an issue: GitHub.