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
- Verify the id exists via the tool list/get API before updating.
- Re-fetch the current tool list to get a fresh valid id.
- Check you are operating against the same environment/tenant where the tool was created.
- 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
- Always load-then-mutate via getById instead of constructing entities with raw ids
- Refresh ids after any delete operation
- Keep environment-specific ids out of shared configs
- Handle the race where a tool is deleted between list and update
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
- TOOL_EXECUTION_ERROR
- BUILD_TOOL_RESULT_ERROR
- MISSING_PARAMS
- Unknown agent status code:
- Unknown agent type code:
AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09).
Data as JSON: /api/errors/63ed929a2bdb3940.
Report an issue: GitHub.