alibaba/spring-ai-alibaba · error · IllegalArgumentException
Invalid status:
Error message
Invalid status:
What it means
AccountStatus.of() throws IllegalArgumentException when the supplied status string matches no AccountStatus constant. The enum defines the allowed account lifecycle states and refuses unknown values rather than silently coercing them.
Source
Thrown at spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-runtime/src/main/java/com/alibaba/cloud/ai/studio/runtime/enums/AccountStatus.java:66
private final Integer status;
/** String representation of the status */
private final String value;
/**
* Get AccountStatus by numeric status code
* @param status numeric status code
* @return corresponding AccountStatus
* @throws IllegalArgumentException if status is invalid
*/
public static AccountStatus of(Integer status) {
for (AccountStatus accountStatus : AccountStatus.values()) {
if (accountStatus.status.equals(status)) {
return accountStatus;
}
}
throw new IllegalArgumentException("Invalid status: " + status);
}
}
View on GitHub (pinned to f82da0b50f)
Solutions
- Pass exactly one of the status strings defined by AccountStatus constants.
- Check case sensitivity and whitespace; normalize with trim()/toUpperCase() if the enum expects uppercase.
- Catch IllegalArgumentException at the boundary and map to a validation error for the client.
- If a new state is required, add a new AccountStatus constant rather than inventing a raw string.
Example fix
// before
AccountStatus st = AccountStatus.of("enabled"); // throws
// after
AccountStatus st = AccountStatus.of("active"); // use a defined value Defensive patterns
Strategy: validation
Validate before calling
boolean valid = Arrays.stream(AccountStatus.values())
.anyMatch(s -> s.getStatus().equals(candidate)); Type guard
Optional<AccountStatus> tryStatus(String s) {
try { return Optional.of(AccountStatus.of(s)); }
catch (IllegalArgumentException e) { return Optional.empty(); }
} Try / catch
try {
st = AccountStatus.of(raw);
} catch (IllegalArgumentException e) {
throw new BadRequestException("Unknown account status: " + raw);
} Prevention
- Restrict admin UI/API inputs to a dropdown fed by AccountStatus.values().
- Normalize case and whitespace of status strings from DB/clients.
- Add a migration check if statuses were renamed between versions.
- Never hand-type status strings; copy from the enum's defined values.
When it happens
Trigger: Calling AccountStatus.of(status) with a string not present in the enum's values (null, empty, or a status stored by another component/version).
Common situations: Reading account rows from a database written by a different schema version; admin UI sending hand-typed status values; case mismatches like "ACTIVE" vs "active".
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/ca7493261a5607a6.
Report an issue: GitHub.