{"record":{"id":"63ed929a2bdb3940","repo":"alibaba/spring-ai-alibaba","slug":"tool-not-found-with-id-id","errorCode":null,"errorMessage":"Tool not found with id: <id>","messagePattern":"Tool not found with id: <id>","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-core/src/main/java/com/alibaba/cloud/ai/studio/core/base/service/impl/ToolServiceImpl.java","lineNumber":70,"sourceCode":"\t\ttoolEntity.setWorkspaceId(requestContext.getWorkspaceId());\n\t\ttoolEntity.setStatus(ToolStatus.PUBLISHED);\n\t\ttoolEntity.setEnabled(true);\n\t\ttoolEntity.setGmtCreate(new Date());\n\t\ttoolEntity.setGmtModified(new Date());\n\t\ttoolEntity.setCreator(requestContext.getAccountId());\n\t\ttoolEntity.setModifier(requestContext.getAccountId());\n\n\t\tsave(toolEntity);\n\t\treturn toolEntity;\n\t}\n\n\t@Override\n\tpublic ToolEntity updateTool(ToolEntity toolEntity) {\n\t\tRequestContext requestContext = RequestContextHolder.getRequestContext();\n\n\t\tToolEntity existing = getById(toolEntity.getId());\n\t\tif (existing == null) {\n\t\t\tthrow new IllegalArgumentException(\"Tool not found with id: \" + toolEntity.getId());\n\t\t}\n\n\t\t// Update fields\n\t\ttoolEntity.setGmtModified(new Date());\n\t\ttoolEntity.setModifier(requestContext.getAccountId());\n\n\t\tupdateById(toolEntity);\n\t\treturn toolEntity;\n\t}\n\n\t@Override\n\tpublic void deleteTool(Long id) {\n\t\tremoveById(id);\n\t}\n\n\t@Override\n\tpublic ToolEntity getToolById(Long id) {\n\t\treturn getById(id);","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-core/src/main/java/com/alibaba/cloud/ai/studio/core/base/service/impl/ToolServiceImpl.java#L52-L88","documentation":"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.","triggerScenarios":"Calling ToolService.updateTool with a ToolEntity whose id is null, was deleted, or belongs to a different namespace/tenant so getById cannot see it.","commonSituations":"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.","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."],"exampleFix":"// before\nToolEntity tool = new ToolEntity();\ntool.setId(clientSuppliedId);\ntoolService.updateTool(tool); // IllegalArgumentException if absent\n// after\nToolEntity tool = toolService.getById(clientSuppliedId);\nif (tool != null) {\n    tool.setDescription(\"updated\");\n    toolService.updateTool(tool);\n}","handlingStrategy":"validation","validationCode":"if (toolId == null || toolService.getById(toolId) == null) { throw new ResourceNotFoundException(\"Tool \" + toolId + \" not found\"); }","typeGuard":null,"tryCatchPattern":"try { toolService.updateTool(entity); } catch (IllegalArgumentException e) { /* map to 404 Not Found response */ }","preventionTips":["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"],"tags":["resource-not-found","tool-management","illegal-argument","admin-server"],"backgroundTag":"entity-not-found","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}