apolloconfig/apollo · error · BadRequestException
type is invalid. type should be in [0, 3].
Error message
type is invalid. type should be in [0, 3].
What it means
A BadRequestException (HTTP 400) thrown from ItemService.checkItemType() when the item type integer is outside the valid range [0, 3]. Apollo items have four type values (typically 0=string, and other types for different formats). The validation is a simple range check: if type < 0 || type > 3, the request is rejected. This check is applied in both save() and update().
Source
Thrown at apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ItemService.java:260
if (parentNamespace != null) {
int parentLimit = getItemValueLengthLimit(parentNamespace);
if (parentLimit > grayNamespaceLimit) {
return parentLimit;
}
}
return grayNamespaceLimit;
}
private boolean checkItemKeyLength(String key) {
if (!StringUtils.isEmpty(key) && key.length() > bizConfig.itemKeyLengthLimit()) {
throw new BadRequestException("key too long. length limit:" + bizConfig.itemKeyLengthLimit());
}
return true;
}
private boolean checkItemType(int type) {
if (type < 0 || type > 3) {
throw new BadRequestException("type is invalid. type should be in [0, 3]. ");
}
return true;
}
private int getItemValueLengthLimit(Namespace namespace) {
Map<Long, Integer> namespaceValueLengthOverride = bizConfig.namespaceValueLengthLimitOverride();
if (namespaceValueLengthOverride != null
&& namespaceValueLengthOverride.containsKey(namespace.getId())) {
return namespaceValueLengthOverride.get(namespace.getId());
}
Map<String, Integer> appIdValueLengthOverride = bizConfig.appIdValueLengthLimitOverride();
if (appIdValueLengthOverride != null
&& appIdValueLengthOverride.containsKey(namespace.getAppId())) {
return appIdValueLengthOverride.get(namespace.getAppId());
}
return bizConfig.itemValueLengthLimit();View on GitHub (pinned to d95fc18d11)
Solutions
- Ensure the item type is one of 0, 1, 2, or 3 before calling save/update.
- Check the Item type constants in the Apollo API to confirm valid values for your server version.
- Default the type to 0 (string) if the client does not explicitly need a different type.
Example fix
// before: invalid type value
itemDTO.setType(5); // out of range -> rejected
// after: use a valid type
itemDTO.setType(0); // 0 is always valid (string type)
// or validate before calling
if (item.getType() < 0 || item.getType() > 3) {
item.setType(0);
} Defensive patterns
Strategy: type-guard
Validate before calling
// Validate item type before saving
if (item.getType() < 0 || item.getType() > 3) {
item.setType(0); // default to valid string type
}
itemService.save(item); Type guard
// Type guard for valid Apollo item types
public static boolean isValidItemType(int type) {
return type >= 0 && type <= 3;
}
// Usage
if (!isValidItemType(itemDTO.getType())) {
itemDTO.setType(0); // default to string
} Prevention
- Always set the item type explicitly to a known valid constant (0-3).
- Validate the type field before calling save/update.
- Default to type 0 when the client does not require a specific type.
- Keep client and server versions in sync to avoid type-constant mismatches.
When it happens
Trigger: ItemService.save() or update() is called with an item whose getType() returns a value less than 0 or greater than 3. For example, setting type to 4, -1, or an uninitialized int field that defaults incorrectly.
Common situations: Client sends a type field that is out of range due to a serialization or mapping bug; a new client version uses a type constant not yet supported by this server version; the type field was left as a garbage/default value.
Related errors
- value too long. length limit:%s
- key too long. length limit:%s
- Comment item's key or value should be blank.
- Comment item's comment should not be blank.
- The maximum number of items (%s) for this namespace has been
AI-assisted analysis of apolloconfig/apollo@d95fc18d11 (2026-08-14).
Data as JSON: /api/errors/2ff920e1ffa36e0b.
Report an issue: GitHub.