{"record":{"id":"2ff920e1ffa36e0b","repo":"apolloconfig/apollo","slug":"type-is-invalid-type-should-be-in-0-3","errorCode":null,"errorMessage":"type is invalid. type should be in [0, 3]. ","messagePattern":"type is invalid\\. type should be in \\[0, 3\\]\\. ","errorType":"exception","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ItemService.java","lineNumber":260,"sourceCode":"    if (parentNamespace != null) {\n      int parentLimit = getItemValueLengthLimit(parentNamespace);\n      if (parentLimit > grayNamespaceLimit) {\n        return parentLimit;\n      }\n    }\n    return grayNamespaceLimit;\n  }\n\n  private boolean checkItemKeyLength(String key) {\n    if (!StringUtils.isEmpty(key) && key.length() > bizConfig.itemKeyLengthLimit()) {\n      throw new BadRequestException(\"key too long. length limit:\" + bizConfig.itemKeyLengthLimit());\n    }\n    return true;\n  }\n\n  private boolean checkItemType(int type) {\n    if (type < 0 || type > 3) {\n      throw new BadRequestException(\"type is invalid. type should be in [0, 3]. \");\n    }\n    return true;\n  }\n\n  private int getItemValueLengthLimit(Namespace namespace) {\n    Map<Long, Integer> namespaceValueLengthOverride = bizConfig.namespaceValueLengthLimitOverride();\n    if (namespaceValueLengthOverride != null\n        && namespaceValueLengthOverride.containsKey(namespace.getId())) {\n      return namespaceValueLengthOverride.get(namespace.getId());\n    }\n\n    Map<String, Integer> appIdValueLengthOverride = bizConfig.appIdValueLengthLimitOverride();\n    if (appIdValueLengthOverride != null\n        && appIdValueLengthOverride.containsKey(namespace.getAppId())) {\n      return appIdValueLengthOverride.get(namespace.getAppId());\n    }\n\n    return bizConfig.itemValueLengthLimit();","sourceCodeStart":242,"sourceCodeEnd":278,"githubUrl":"https://github.com/apolloconfig/apollo/blob/d95fc18d112589efc09ddcbe1507047584d55251/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ItemService.java#L242-L278","documentation":"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().","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before: invalid type value\nitemDTO.setType(5); // out of range -> rejected\n\n// after: use a valid type\nitemDTO.setType(0); // 0 is always valid (string type)\n// or validate before calling\nif (item.getType() < 0 || item.getType() > 3) {\n    item.setType(0);\n}","handlingStrategy":"type-guard","validationCode":"// Validate item type before saving\nif (item.getType() < 0 || item.getType() > 3) {\n    item.setType(0); // default to valid string type\n}\nitemService.save(item);","typeGuard":"// Type guard for valid Apollo item types\npublic static boolean isValidItemType(int type) {\n    return type >= 0 && type <= 3;\n}\n\n// Usage\nif (!isValidItemType(itemDTO.getType())) {\n    itemDTO.setType(0); // default to string\n}","tryCatchPattern":null,"preventionTips":["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."],"tags":["item","type","validation","bad-request","apollo-biz"],"backgroundTag":null,"analyzedSha":"d95fc18d112589efc09ddcbe1507047584d55251","analyzedAt":"2026-08-14T04:00:05.477Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}