alibaba/spring-ai-alibaba · error · IllegalArgumentException

Experiment not found:

Error message

Experiment not found: 

What it means

Thrown by ExperimentServiceImpl.stop when experimentMapper.selectById(id) returns null: no experiment exists with the given ID, so there is nothing to stop. It is an IllegalArgumentException carrying the offending ID in the message.

Source

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

                (long) request.getPageNumber(),
                (long) request.getPageSize(),
                resultItems);

    }

    @Override
    @Transactional
    public Experiment stop(Long id) {
        log.info("停止实验: {}", id);
        
        if (id == null) {
            throw new IllegalArgumentException("Experiment ID cannot be null");
        }
        
        // 获取实验信息
        ExperimentDO experimentDO = experimentMapper.selectById(id);
        if (experimentDO == null) {
            throw new IllegalArgumentException("Experiment not found: " + id);
        }



        // 检查实验状态
        if (ExperimentStatus.COMPLETED.getCode().equals(experimentDO.getStatus()) ||
            ExperimentStatus.FAILED.getCode().equals(experimentDO.getStatus()) ||
            ExperimentStatus.STOPPED.getCode().equals(experimentDO.getStatus())) {
            log.warn("实验 {} 状态为 {},无法停止", id, experimentDO.getStatus());
            return Experiment.fromDO(experimentDO);
        }


        
        // 更新实验状态为已停止
        experimentDO.setStatus(String.valueOf(ExperimentStatus.STOPPED));
        experimentDO.setUpdateTime(LocalDateTime.now());
        

View on GitHub (pinned to f82da0b50f)

Solutions

  1. Verify the experiment ID exists (getById) before calling stop
  2. Catch the IllegalArgumentException and surface 404 to the client instead of 500
  3. Confirm client and server point at the same environment/database
  4. Handle concurrent-stop races by treating not-found as idempotent success

Example fix

// before
if (experimentDO == null) {
    throw new IllegalArgumentException("Experiment not found: " + id);
}
// after
if (experimentDO == null) {
    throw new ExperimentNotFoundException(id); // mapped to 404 by exception handler
}
Defensive patterns

Strategy: validation

Validate before calling

if (experimentService.getById(id) == null) throw new ExperimentNotFoundException(id);

Type guard

boolean experimentExists(Long id) { return id != null && experimentService.getById(id) != null; }

Try / catch

try { experimentService.stop(id); } catch (IllegalArgumentException e) { log.warn("Stop for missing experiment {}", id); /* treat as idempotent success or 404 */ }

Prevention

When it happens

Trigger: Stopping an experiment ID that was deleted, never created, already completed and purged, or exists only in a different environment/datasource.

Common situations: Double-stop: the second request races with cleanup or the record was removed; stale experiment list in the UI; switching between dev and prod databases; typo'd or truncated ID.

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


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