{"record":{"id":"e645897db89d418b","repo":"elunez/eladmin","slug":"cron","errorCode":null,"errorMessage":"cron表达式格式错误","messagePattern":"cron表达式格式错误","errorType":"exception","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"eladmin-system/src/main/java/me/zhengjie/modules/quartz/service/impl/QuartzJobServiceImpl.java","lineNumber":82,"sourceCode":"    }\n\n    @Override\n    public List<QuartzLog> queryAllLog(JobQueryCriteria criteria) {\n        return quartzLogRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder));\n    }\n\n    @Override\n    public QuartzJob findById(Long id) {\n        QuartzJob quartzJob = quartzJobRepository.findById(id).orElseGet(QuartzJob::new);\n        ValidationUtil.isNull(quartzJob.getId(),\"QuartzJob\",\"id\",id);\n        return quartzJob;\n    }\n\n    @Override\n    @Transactional(rollbackFor = Exception.class)\n    public void create(QuartzJob resources) {\n        if (!CronExpression.isValidExpression(resources.getCronExpression())){\n            throw new BadRequestException(\"cron表达式格式错误\");\n        }\n        resources = quartzJobRepository.save(resources);\n        quartzManage.addJob(resources);\n    }\n\n    @Override\n    @Transactional(rollbackFor = Exception.class)\n    public void update(QuartzJob resources) {\n        if (!CronExpression.isValidExpression(resources.getCronExpression())){\n            throw new BadRequestException(\"cron表达式格式错误\");\n        }\n        if(StringUtils.isNotBlank(resources.getSubTask())){\n            List<String> tasks = Arrays.asList(resources.getSubTask().split(\"[,，]\"));\n            if (tasks.contains(resources.getId().toString())) {\n                throw new BadRequestException(\"子任务中不能添加当前任务ID\");\n            }\n        }\n        resources = quartzJobRepository.save(resources);","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/elunez/eladmin/blob/55fbf705956949697dbd68bf9003776609d3d029/eladmin-system/src/main/java/me/zhengjie/modules/quartz/service/impl/QuartzJobServiceImpl.java#L64-L100","documentation":"QuartzJobServiceImpl.create validates the job's cronExpression with Quartz's CronExpression.isValidExpression before saving and scheduling. An invalid 6/7-field cron string (seconds minutes hours day-of-month month day-of-week [year]) throws this BadRequestException and the transaction rolls back, so no job row or trigger is created.","triggerScenarios":"POST /api/quartz/jobs (or the equivalent UI action) with a malformed cron such as '0 0 * * *' (5-field Linux crontab syntax), 'every 5 minutes', '* * *', or fields out of range. Quartz cron requires exactly 6 or 7 space-separated fields and its own special-character rules.","commonSituations":"Developers pasting Unix crontab syntax (5 fields) — the single most common cause; using '?' on the wrong field; day-of-week names vs numbers confusion; spaces instead of nothing between fields; online cron generators that target Linux cron rather than Quartz.","solutions":["Convert the expression to Quartz format with a seconds field: '0 0/5 * * * ?' means every 5 minutes starting at second 0.","Validate locally with org.quartz.CronExpression.isValidExpression(expr) before submitting.","Use a Quartz-aware cron generator and remember day-of-month and day-of-week cannot both be '*' — one must be '?'."],"exampleFix":"// before (Linux crontab syntax, 5 fields -> rejected)\n\"*/5 * * * *\"\n// after (Quartz syntax, 6 fields)\n\"0 */5 * * * ?\"","handlingStrategy":"validation","validationCode":"// validate before submit, using the same Quartz validator the server uses\nimport org.quartz.CronExpression;\nif (!CronExpression.isValidExpression(expr)) {\n    throw new IllegalArgumentException(\"Invalid Quartz cron (need 6-7 fields): \" + expr);\n}","typeGuard":"boolean isValidQuartzCron(String s) {\n    return s != null && org.quartz.CronExpression.isValidExpression(s.trim());\n}","tryCatchPattern":null,"preventionTips":["Remember Quartz cron has 6 fields and starts with SECONDS — never paste 5-field Linux crontab entries.","Use a Quartz-specific cron builder UI in the frontend.","Add the org.quartz dependency to the frontend's BFF or use a JS quartz-cron validator for instant feedback."],"tags":["quartz","cron","validation"],"backgroundTag":null,"analyzedSha":"55fbf705956949697dbd68bf9003776609d3d029","analyzedAt":"2026-08-14T11:56:12.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}