alibaba/spring-ai-alibaba · error · IllegalArgumentException

Tool not found with id: <id>

Error message

Tool not found with id: <id>

What it means

updateTool throws a plain IllegalArgumentException when no ToolEntity exists with the given id — the getById lookup returned null. This is an optimistic pre-check guarding against updating a non-existent tool; the message includes the offending id.

Source

Thrown at spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-core/src/main/java/com/alibaba/cloud/ai/studio/core/base/service/impl/ToolServiceImpl.java:70

		toolEntity.setWorkspaceId(requestContext.getWorkspaceId());
		toolEntity.setStatus(ToolStatus.PUBLISHED);
		toolEntity.setEnabled(true);
		toolEntity.setGmtCreate(new Date());
		toolEntity.setGmtModified(new Date());
		toolEntity.setCreator(requestContext.getAccountId());
		toolEntity.setModifier(requestContext.getAccountId());

		save(toolEntity);
		return toolEntity;
	}

	@Override
	public ToolEntity updateTool(ToolEntity toolEntity) {
		RequestContext requestContext = RequestContextHolder.getRequestContext();

		ToolEntity existing = getById(toolEntity.getId());
		if (existing == null) {
			throw new IllegalArgumentException("Tool not found with id: " + toolEntity.getId());
		}

		// Update fields
		toolEntity.setGmtModified(new Date());
		toolEntity.setModifier(requestContext.getAccountId());

		updateById(toolEntity);
		return toolEntity;
	}

	@Override
	public void deleteTool(Long id) {
		removeById(id);
	}

	@Override
	public ToolEntity getToolById(Long id) {
		return getById(id);

View on GitHub (pinned to f82da0b50f)

Solutions

  1. Verify the id exists via the tool list/get API before updating.
  2. Re-fetch the current tool list to get a fresh valid id.
  3. Check you are operating against the same environment/tenant where the tool was created.
  4. Ensure the entity is loaded via getById and mutated, rather than constructed with a fabricated id.

Example fix

// before
ToolEntity tool = new ToolEntity();
tool.setId(clientSuppliedId);
toolService.updateTool(tool); // IllegalArgumentException if absent
// after
ToolEntity tool = toolService.getById(clientSuppliedId);
if (tool != null) {
    tool.setDescription("updated");
    toolService.updateTool(tool);
}
Defensive patterns

Strategy: validation

Validate before calling

if (toolId == null || toolService.getById(toolId) == null) { throw new ResourceNotFoundException("Tool " + toolId + " not found"); }

Try / catch

try { toolService.updateTool(entity); } catch (IllegalArgumentException e) { /* map to 404 Not Found response */ }

Prevention

When it happens

Trigger: Calling ToolService.updateTool with a ToolEntity whose id is null, was deleted, or belongs to a different namespace/tenant so getById cannot see it.

Common situations: Client holding a stale tool id after the tool was deleted; id never set on a newly constructed entity before update; cross-environment id (id from staging used in production); race where another user deleted the tool between listing and updating.

Understand the failure class

Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.

Related errors


AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09). Data as JSON: /api/errors/63ed929a2bdb3940. Report an issue: GitHub.