{"record":{"id":"b9eb7a4afe913c57","repo":"apolloconfig/apollo","slug":"item-not-exist-id-s","errorCode":null,"errorMessage":"item not exist. ID:%s","messagePattern":"item not exist\\. ID:(.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":500,"severity":"error","filePath":"apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ItemService.java","lineNumber":65,"sourceCode":"  private final NamespaceService namespaceService;\n  private final AuditService auditService;\n  private final BizConfig bizConfig;\n\n  public ItemService(final ItemRepository itemRepository,\n      final @Lazy NamespaceService namespaceService, final AuditService auditService,\n      final BizConfig bizConfig) {\n    this.itemRepository = itemRepository;\n    this.namespaceService = namespaceService;\n    this.auditService = auditService;\n    this.bizConfig = bizConfig;\n  }\n\n\n  @Transactional\n  public Item delete(long id, String operator) {\n    Item item = itemRepository.findById(id).orElse(null);\n    if (item == null) {\n      throw new IllegalArgumentException(\"item not exist. ID:\" + id);\n    }\n\n    item.setDeleted(true);\n    item.setDataChangeLastModifiedBy(operator);\n    Item deletedItem = itemRepository.save(item);\n\n    auditService.audit(Item.class.getSimpleName(), id, Audit.OP.DELETE, operator);\n    return deletedItem;\n  }\n\n  @Transactional\n  public int batchDelete(long namespaceId, String operator) {\n    return itemRepository.deleteByNamespaceId(namespaceId, operator);\n\n  }\n\n  public Item findOne(String appId, String clusterName, String namespaceName, String key) {\n    Namespace namespace =","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/apolloconfig/apollo/blob/d95fc18d112589efc09ddcbe1507047584d55251/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ItemService.java#L47-L83","documentation":"An IllegalArgumentException thrown from ItemService.delete(long id, String operator) when itemRepository.findById(id) returns null (item not found). Unlike most Apollo errors which use AbstractApolloHttpException subclasses, this uses a raw IllegalArgumentException — it is a programming/contract error indicating the caller tried to delete an item that does not exist. In a Spring context without a custom handler this typically surfaces as HTTP 500.","triggerScenarios":"ItemService.delete(id, operator) is called with an item id that does not exist in the database (findById returns empty/null). This can happen through the admin-service item-delete endpoint or internally from the NamespaceAcquireLockAspect delete-item advice (which first loads the item to get the namespaceId).","commonSituations":"The item was already deleted by another request or user; the item id was stale or incorrect; a race condition where the item was removed between a listing call and the delete call; soft-deleted items that are no longer found by findById.","solutions":["Check that the item exists (itemService.findOne(id) returns non-null) before calling delete.","If the item is already deleted, treat the operation as a no-op success (idempotent delete).","Verify the item id is correct and corresponds to the intended namespace."],"exampleFix":"// before: delete without checking existence\nitemService.delete(itemId, operator);\n\n// after: idempotent delete\nItem item = itemService.findOne(itemId);\nif (item != null) {\n    itemService.delete(itemId, operator);\n} else {\n    // already deleted or never existed — no-op\n}","handlingStrategy":"validation","validationCode":"// Check item existence before deleting (idempotent delete)\nItem item = itemService.findOne(id);\nif (item == null) {\n    logger.info(\"Item {} already deleted or does not exist\", id);\n    return; // treat as success\n}\nitemService.delete(id, operator);","typeGuard":null,"tryCatchPattern":"try {\n    itemService.delete(itemId, operator);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"item not exist\")) {\n        // already deleted — no-op\n        logger.info(\"Item {} already deleted\", itemId);\n    } else {\n        throw e;\n    }\n}","preventionTips":["Check item existence with findOne() before calling delete() for idempotent deletes.","Treat 'already deleted' as a success case in idempotent workflows.","Verify item ids from recent listing calls to avoid stale references."],"tags":["item","not-found","illegal-argument","delete","apollo-biz"],"backgroundTag":null,"analyzedSha":"d95fc18d112589efc09ddcbe1507047584d55251","analyzedAt":"2026-08-14T04:00:05.477Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}