{"record":{"id":"d0cc00d5f6c9097a","repo":"alibaba/spring-ai-alibaba","slug":"id-0","errorCode":null,"errorMessage":"数据项ID不能为空且必须大于0","messagePattern":"数据项ID不能为空且必须大于0","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-start/src/main/java/com/alibaba/cloud/ai/studio/admin/service/impl/DatasetItemServiceImpl.java","lineNumber":162,"sourceCode":"\n        if(Objects.isNull(existingData)){\n            log.warn(\"尝试更新不存在的数据项: {}\", request.getId());\n        }\n\n\n        datasetItemMapper.update(request.getId(),request.getDataContent());\n\n        return getById(request.getId());\n    }\n\n    @Override\n\n    public void deleteById(Long id) {\n        log.info(\"删除数据项: {}\", id);\n        \n        // 数据验证\n        if (id == null || id <= 0) {\n            throw new IllegalArgumentException(\"数据项ID不能为空且必须大于0\");\n        }\n        \n        // 检查数据项是否存在\n        DatasetItemDO existingItem = datasetItemMapper.selectById(id);\n        if (existingItem == null) {\n            log.warn(\"尝试删除不存在的数据项: {}\", id);\n            throw new RuntimeException(\"数据项不存在: \" + id);\n        }\n        \n\n        int result = datasetItemMapper.deleteById(id);\n        if (result <= 0) {\n            log.error(\"数据项删除失败: {}\", id);\n            throw new RuntimeException(\"数据项删除失败: \" + id);\n        }\n        \n        log.info(\"数据项删除成功: {}\", id);\n    }","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-start/src/main/java/com/alibaba/cloud/ai/studio/admin/service/impl/DatasetItemServiceImpl.java#L144-L180","documentation":"Thrown by DatasetItemServiceImpl.deleteById() as an IllegalArgumentException when the id argument is null or <= 0. The service validates input before touching the database because MyBatis-Plus selectById/deleteById with a null id fails unclearly.","triggerScenarios":"Calling deleteById(null), deleteById(0L), or deleteById with a negative id, typically from an unbound or default-initialized controller parameter.","commonSituations":"Missing path/query parameter mapped to a null Long; client sending 0 or garbage that parses to a non-positive value; uninitialized field defaults.","solutions":["Ensure the caller passes a valid positive dataset item id","Add @NotNull / @Positive bean-validation on the controller parameter","Check the client request actually includes the id (no dropped path variable)","Return a 400 response for invalid ids instead of letting it bubble as 500"],"exampleFix":"// before\nLong id = extractId(request); // may be null\ndatasetItemService.deleteById(id);\n// after\nif (id == null || id <= 0) { throw new IllegalArgumentException(\"id must be a positive number\"); }\ndatasetItemService.deleteById(id);","handlingStrategy":"validation","validationCode":"if (id == null || id <= 0) { throw new IllegalArgumentException(\"id must be positive\"); }","typeGuard":"boolean isValidItemId(Long id) { return id != null && id > 0; }","tryCatchPattern":"try { service.deleteById(id); } catch (IllegalArgumentException e) { return ResponseEntity.badRequest().body(e.getMessage()); }","preventionTips":["Use @NotNull @Positive bean validation on controller parameters","Never bind ids from unvalidated query strings directly","Treat 0/negative ids as client bugs and return 400"],"tags":["validation","argument"],"backgroundTag":"missing-required-argument","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}