{"record":{"id":"a821878f5ae7fc13","repo":"alibaba/spring-ai-alibaba","slug":"version-id-cannot-be-null","errorCode":null,"errorMessage":"Version ID cannot be null","messagePattern":"Version ID cannot be null","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/DatasetVersionServiceImpl.java","lineNumber":127,"sourceCode":"        PageResult<DatasetVersion> result = new PageResult<>();\n        result.setTotalCount((long) totalCount);\n        result.setTotalPage(totalPages);\n        result.setPageNumber((long) request.getPageNumber());\n        result.setPageSize((long) request.getPageSize());\n        result.setPageItems(datasetVersions);\n\n        log.info(\"Dataset version list query completed, total: {}, current page: {}\", totalCount, request.getPageNumber());\n        return result;\n    }\n\n    @Override\n    @Transactional\n    public DatasetVersion update(DatasetVersionUpdateRequest request) {\n        log.info(\"Updating dataset version: {}\", request);\n\n        // Validate request\n        if (request.getDatasetVersionId() == null) {\n            throw new IllegalArgumentException(\"Version ID cannot be null\");\n        }\n\n\n        // Note: Version number updates are not supported in this implementation\n        // to maintain data integrity and prevent conflicts\n\n        // Update fields - only update available fields\n        int result = datasetVersionMapper.update(\n                request.getDatasetVersionId(),\n                request.getDescription(),\n                request.getStatus()\n        );\n\n        if (result <= 0) {\n            throw new RuntimeException(\"Failed to update dataset version\");\n        }\n\n        // Get updated version","sourceCodeStart":109,"sourceCodeEnd":145,"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/DatasetVersionServiceImpl.java#L109-L145","documentation":"DatasetVersionServiceImpl.update() validates the request before applying changes. Since updates are keyed by datasetVersionId, a null ID makes the update meaningless, so an IllegalArgumentException is thrown up front instead of issuing a doomed database update. It is a guard against a malformed request body.","triggerScenarios":"Calling update(DatasetVersionUpdateRequest) via the service or its REST endpoint with a request whose datasetVersionId field is null (e.g. omitted in JSON payload, or constructed programmatically without setting the ID).","commonSituations":"Clients POST/PUT a JSON body with only description/status fields forgetting the id; deserialization leaves the field null because the JSON key is misspelled (e.g. versionId instead of datasetVersionId); new-request objects reused for create instead of update.","solutions":["Set request.setDatasetVersionId(...) with the existing version's ID before calling update.","Fix the JSON payload so the field is named datasetVersionId and is non-null.","Add a @NotNull / Bean Validation annotation on DatasetVersionUpdateRequest.datasetVersionId so Spring rejects bad payloads with 400 before reaching the service."],"exampleFix":"// before\nDatasetVersionUpdateRequest req = new DatasetVersionUpdateRequest();\nreq.setDescription(\"v2 notes\");\nservice.update(req); // throws\n// after\nreq.setDatasetVersionId(42L);\nservice.update(req);","handlingStrategy":"validation","validationCode":"if (request == null || request.getDatasetVersionId() == null) {\n    throw new IllegalArgumentException(\"datasetVersionId is required for update\");\n}","typeGuard":"boolean hasId(DatasetVersionUpdateRequest r) { return r != null && r.getDatasetVersionId() != null; }","tryCatchPattern":"try {\n    service.update(request);\n} catch (IllegalArgumentException e) {\n    return ResponseEntity.badRequest().body(Map.of(\"error\", e.getMessage()));\n}","preventionTips":["Always load the version (getById) before constructing the update request.","Use Bean Validation @NotNull on DatasetVersionUpdateRequest.datasetVersionId.","In API clients, send the exact field name datasetVersionId in JSON payloads."],"tags":["validation","null-check","dataset-version","illegal-argument"],"backgroundTag":"null-argument","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"}