{"record":{"id":"fbfc1aa786d27fde","repo":"alibaba/spring-ai-alibaba","slug":"experiment-id-cannot-be-null","errorCode":null,"errorMessage":"Experiment ID cannot be null","messagePattern":"Experiment ID cannot be null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"warning","filePath":"spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-start/src/main/java/com/alibaba/cloud/ai/studio/admin/service/impl/ExperimentServiceImpl.java","lineNumber":137,"sourceCode":"        // 获取总数\n        int totalCount = experimentMapper.count(request.getName(), status);\n\n        return new PageResult<>(\n                (long) totalCount,\n                (long) request.getPageNumber(),\n                (long) request.getPageSize(),\n                experimentDOList.stream()\n                        .map(Experiment::fromDO)\n                        .toList());\n\n    }\n\n    @Override\n    public Experiment getById(Long id) {\n        log.info(\"查询实验详情: {}\", id);\n        \n        if (id == null) {\n            throw new IllegalArgumentException(\"Experiment ID cannot be null\");\n        }\n        \n        ExperimentDO experimentDO = experimentMapper.selectById(id);\n        if (experimentDO == null) {\n            log.warn(\"未找到ID为{}的实验\", id);\n            return null;\n        }\n\n        Experiment experiment = Experiment.fromDO(experimentDO);\n\n        List<EvaluatorConfig> evaluatorConfigList = JSON.parseArray(experiment.getEvaluatorConfig(), EvaluatorConfig.class);\n\n        evaluatorConfigList.stream()\n                .filter(Objects::nonNull)\n                .forEach(evaluatorConfig -> {\n                    try {\n                        EvaluatorDO evaluatorDO = evaluatorMapper.selectById(evaluatorConfig.getEvaluatorId());\n                        evaluatorConfig.setEvaluatorName(evaluatorDO != null ? evaluatorDO.getName() : \"Unknown Evaluator\");","sourceCodeStart":119,"sourceCodeEnd":155,"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/ExperimentServiceImpl.java#L119-L155","documentation":"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.","triggerScenarios":"Calling getById(null) directly, or a controller path variable failing to bind (e.g. missing path segment) so the service receives null.","commonSituations":"Client calling /experiments/ (trailing slash, empty ID); deserialization producing a null field; programmatic callers skipping the null check before the service call.","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"],"exampleFix":"// before\nExperiment exp = experimentService.getById(experimentIdOrNull);\n// after\nif (experimentId == null || experimentId <= 0) {\n    throw new IllegalArgumentException(\"experimentId is required\");\n}\nExperiment exp = experimentService.getById(experimentId);","handlingStrategy":"validation","validationCode":"if (id == null) throw new IllegalArgumentException(\"Experiment ID is required\");","typeGuard":"boolean hasExperimentId(Long id) { return id != null && id > 0; }","tryCatchPattern":"try { return experimentService.getById(id); } catch (IllegalArgumentException e) { throw new ResponseStatusException(HttpStatus.BAD_REQUEST, e.getMessage()); }","preventionTips":["Use @NotNull validation on controller params","Never call service methods with unbound path variables","Default missing IDs to a 400 at the API edge"],"tags":["null","argument-validation","experiment"],"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"}