apolloconfig/apollo · error · IllegalArgumentException

item not exist. ID:%s

Error message

item not exist. ID:%s

What it means

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.

Source

Thrown at apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ItemService.java:65

  private final NamespaceService namespaceService;
  private final AuditService auditService;
  private final BizConfig bizConfig;

  public ItemService(final ItemRepository itemRepository,
      final @Lazy NamespaceService namespaceService, final AuditService auditService,
      final BizConfig bizConfig) {
    this.itemRepository = itemRepository;
    this.namespaceService = namespaceService;
    this.auditService = auditService;
    this.bizConfig = bizConfig;
  }


  @Transactional
  public Item delete(long id, String operator) {
    Item item = itemRepository.findById(id).orElse(null);
    if (item == null) {
      throw new IllegalArgumentException("item not exist. ID:" + id);
    }

    item.setDeleted(true);
    item.setDataChangeLastModifiedBy(operator);
    Item deletedItem = itemRepository.save(item);

    auditService.audit(Item.class.getSimpleName(), id, Audit.OP.DELETE, operator);
    return deletedItem;
  }

  @Transactional
  public int batchDelete(long namespaceId, String operator) {
    return itemRepository.deleteByNamespaceId(namespaceId, operator);

  }

  public Item findOne(String appId, String clusterName, String namespaceName, String key) {
    Namespace namespace =

View on GitHub (pinned to d95fc18d11)

Solutions

  1. Check that the item exists (itemService.findOne(id) returns non-null) before calling delete.
  2. If the item is already deleted, treat the operation as a no-op success (idempotent delete).
  3. Verify the item id is correct and corresponds to the intended namespace.

Example fix

// before: delete without checking existence
itemService.delete(itemId, operator);

// after: idempotent delete
Item item = itemService.findOne(itemId);
if (item != null) {
    itemService.delete(itemId, operator);
} else {
    // already deleted or never existed — no-op
}
Defensive patterns

Strategy: validation

Validate before calling

// Check item existence before deleting (idempotent delete)
Item item = itemService.findOne(id);
if (item == null) {
    logger.info("Item {} already deleted or does not exist", id);
    return; // treat as success
}
itemService.delete(id, operator);

Try / catch

try {
    itemService.delete(itemId, operator);
} catch (IllegalArgumentException e) {
    if (e.getMessage().contains("item not exist")) {
        // already deleted — no-op
        logger.info("Item {} already deleted", itemId);
    } else {
        throw e;
    }
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of apolloconfig/apollo@d95fc18d11 (2026-08-14). Data as JSON: /api/errors/b9eb7a4afe913c57. Report an issue: GitHub.