alibaba/spring-ai-alibaba · warning · IllegalArgumentException
Experiment ID cannot be null
Error message
Experiment ID cannot be null
What it means
Input validation failure in ExperimentServiceImpl.getById. The method requires a non-null experiment id before querying; passing null would be an ill-formed lookup, so IllegalArgumentException is thrown immediately. This is a generic guard against programming errors in callers (e.g., an unset id field) rather than a user-facing condition; callers should ensure the id is populated before invoking the lookup.
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:137
// 获取总数
int totalCount = experimentMapper.count(request.getName(), status);
return new PageResult<>(
(long) totalCount,
(long) request.getPageNumber(),
(long) request.getPageSize(),
experimentDOList.stream()
.map(Experiment::fromDO)
.toList());
}
@Override
public Experiment getById(Long id) {
log.info("查询实验详情: {}", id);
if (id == null) {
throw new IllegalArgumentException("Experiment ID cannot be null");
}
ExperimentDO experimentDO = experimentMapper.selectById(id);
if (experimentDO == null) {
log.warn("未找到ID为{}的实验", id);
return null;
}
Experiment experiment = Experiment.fromDO(experimentDO);
List<EvaluatorConfig> evaluatorConfigList = JSON.parseArray(experiment.getEvaluatorConfig(), EvaluatorConfig.class);
evaluatorConfigList.stream()
.filter(Objects::nonNull)
.forEach(evaluatorConfig -> {
try {
EvaluatorDO evaluatorDO = evaluatorMapper.selectById(evaluatorConfig.getEvaluatorId());
evaluatorConfig.setEvaluatorName(evaluatorDO != null ? evaluatorDO.getName() : "Unknown Evaluator");View on GitHub (pinned to f82da0b50f)
Solutions
- Ensure the request actually contains the experiment ID before calling the service
- Use @PathVariable validation (e.g. @NotNull / spring-boot-starter-validation) at the controller layer
- Add a null guard in the client code calling getById
Example fix
// before
Experiment exp = experimentService.getById(experimentIdOrNull);
// after
if (experimentId == null || experimentId <= 0) {
throw new IllegalArgumentException("experimentId is required");
}
Experiment exp = experimentService.getById(experimentId); Defensive patterns
Strategy: validation
Validate before calling
if (id == null) throw new IllegalArgumentException("Experiment ID is required"); Type guard
boolean hasExperimentId(Long id) { return id != null && id > 0; } Try / catch
try { return experimentService.getById(id); } catch (IllegalArgumentException e) { throw new ResponseStatusException(HttpStatus.BAD_REQUEST, e.getMessage()); } Prevention
- Use @NotNull validation on controller params
- Never call service methods with unbound path variables
- Default missing IDs to a 400 at the API edge
When it happens
Trigger: Calling getById(null) directly, or a controller path variable failing to bind (e.g. missing path segment) so the service receives null.
Common situations: Client calling /experiments/ (trailing slash, empty ID); deserialization producing a null field; programmatic callers skipping the null check before the service call.
Related errors
- oss object name is invalid
- Evaluator version ID cannot be null
- Failed to create experiment
- Invalid page number or page size
- Experiment not found:
AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09).
Data as JSON: /api/errors/fbfc1aa786d27fde.
Report an issue: GitHub.