alibaba/spring-ai-alibaba · warning

未找到ID为{}的评测集

Error message

未找到ID为{}的评测集

What it means

DatasetServiceImpl.getById loads a DatasetDO by primary key. When no row matches, it logs '未找到ID为{}的评测集' (no dataset with this id) and returns null rather than throwing; callers must null-check or they will NPE on the returned value.

Source

Thrown at spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-start/src/main/java/com/alibaba/cloud/ai/studio/admin/service/impl/DatasetServiceImpl.java:112

        

        PageResult<Dataset> result = new PageResult<>(
                (long) total, 
                (long) pageNumber, 
                (long) pageSize,
                datasetList
        );
        
        return result;
    }

    @Override
    public Dataset getById(Long id) {
        log.info("查询评测集详情: {}", id);
        DatasetDO datasetDO = datasetMapper.selectById(id);
            
        if (datasetDO == null) {
            log.warn("未找到ID为{}的评测集", id);
            return null;
        }
        Dataset dataset = Dataset.fromDO(datasetDO);

        DatasetVersionDO datasetVersionDO = datasetVersionMapper.selectLatestVersion(dataset.getId());

        if(Objects.nonNull(datasetVersionDO)){
            dataset.setDataCount(datasetVersionDO.getDataCount());
            dataset.setLatestVersion(datasetVersionDO.getVersion());
            dataset.setLatestVersionId(datasetVersionDO.getId());
        }
        
        return dataset;
    }

    @Override
    public Dataset update(DatasetUpdateRequest request) {
        log.info("更新评测集: {}", request);

View on GitHub (pinned to f82da0b50f)

Solutions

  1. Null-check the return value before use
  2. Verify the dataset id against the actual table (SELECT * FROM dataset WHERE id=...)
  3. Return a proper not-found signal (Optional or 404) from the API layer instead of null
  4. Confirm you are querying the intended database/schema/environment

Example fix

// before
Dataset d = datasetService.getById(id);
d.getVersions(); // NPE when not found
// after
Dataset d = datasetService.getById(id);
if (d == null) { throw new ResponseStatusException(HttpStatus.NOT_FOUND, "dataset not found: " + id); }
Defensive patterns

Strategy: type-guard

Validate before calling

if (id == null || id <= 0) throw new IllegalArgumentException("dataset id must be a positive number");
// optionally: SELECT count(*) FROM dataset WHERE id = ? first

Type guard

Dataset d = datasetService.getById(id);
if (d == null) { /* not found: return 404 or create */ }

Try / catch

Dataset d = datasetService.getById(id);
if (d == null) {
    throw new ResponseStatusException(HttpStatus.NOT_FOUND, "dataset " + id + " not found");
}

Prevention

When it happens

Trigger: getById(id) with an id not present in the dataset table — deleted dataset, wrong id, id from a different environment, or the row exists but selectById is scoped/filtered.

Common situations: Frontend holding a link to a deleted evaluation dataset; hardcoded test ids; multi-tenant filtering hiding the row; dev/prod database mix-up.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


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