{"record":{"id":"cbe4b51ff4091691","repo":"alibaba/spring-cloud-alibaba","slug":"cron-and-onetime-shouldn-t-set-together","errorCode":null,"errorMessage":"cron and oneTime shouldn't set together","messagePattern":"cron and oneTime shouldn't set together","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-schedulerx/src/main/java/com/alibaba/cloud/scheduling/schedulerx/service/JobSyncService.java","lineNumber":278,"sourceCode":"\n\t\tif (SchedulerxConstants.JOB_MODEL_MAPREDUCE_ALIAS.equals(jobProperty.getJobModel())) {\n\t\t\trequest.setExecuteMode(ExecuteMode.BATCH.getKey());\n\t\t}\n\t\telse {\n\t\t\trequest.setExecuteMode(jobProperty.getJobModel());\n\t\t}\n\t\tif (StringUtils.isNotEmpty(jobProperty.getDescription())) {\n\t\t\trequest.setDescription(jobProperty.getDescription());\n\t\t}\n\n\t\tif (StringUtils.isNotEmpty(jobProperty.getContent())) {\n\t\t\trequest.setContent(jobProperty.getContent());\n\t\t}\n\n\t\tString cron = jobProperty.getCron();\n\t\tString oneTime = jobProperty.getOneTime();\n\t\tif (StringUtils.isNotEmpty(cron) && StringUtils.isNotEmpty(oneTime)) {\n\t\t\tthrow new IOException(\"cron and oneTime shouldn't set together\");\n\t\t}\n\t\tif (cron != null && !cron.isEmpty()) {\n\t\t\tCronExpression cronExpression = new CronExpression(cron);\n\t\t\tDate now = new Date();\n\t\t\tDate nextData = cronExpression.getTimeAfter(now);\n\t\t\tDate next2Data = nextData == null ? null : cronExpression.getTimeAfter(nextData);\n\t\t\tif (nextData != null && next2Data != null) {\n\t\t\t\tlong interval = TimeUnit.MILLISECONDS.toSeconds((next2Data.getTime() - nextData.getTime()));\n\t\t\t\tif (interval < SchedulerxConstants.SECOND_DELAY_MAX_VALUE) {\n\t\t\t\t\trequest.setTimeType(TimeType.SECOND_DELAY.getValue());\n\t\t\t\t\trequest.setTimeExpression(String.valueOf(interval < SchedulerxConstants.SECOND_DELAY_MIN_VALUE ?\n\t\t\t\t\t\t\tSchedulerxConstants.SECOND_DELAY_MIN_VALUE : interval));\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\trequest.setTimeType(TimeType.CRON.getValue());\n\t\t\t\t\trequest.setTimeExpression(cron);\n\t\t\t\t}\n\t\t\t}","sourceCodeStart":260,"sourceCodeEnd":296,"githubUrl":"https://github.com/alibaba/spring-cloud-alibaba/blob/115d5901102009492e05d5ec18c3f79cad4077d0/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-schedulerx/src/main/java/com/alibaba/cloud/scheduling/schedulerx/service/JobSyncService.java#L260-L296","documentation":"Thrown by JobSyncService.createJob when a job declared under spring.cloud.scheduling.schedulerx.jobs sets BOTH 'cron' and 'oneTime'. SchedulerX2 models a job as either a recurring schedule (cron) or a single fire-at time (oneTime); specifying both is ambiguous and the create path rejects it with IOException before issuing the CreateJob POP request.","triggerScenarios":"For each entry in spring.cloud.scheduling.schedulerx.jobs, createJob reads jobProperty.getCron() and jobProperty.getOneTime(); if StringUtils.isNotEmpty(cron) && StringUtils.isNotEmpty(oneTime) at JobSyncService.java:277-278, it throws. Triggered during job sync for a job that has both keys populated.","commonSituations":"Copy-pasting a job definition and leaving a stale 'oneTime' next to a new 'cron'; misunderstanding that oneTime is a one-shot ISO timestamp and not a fallback; YAML alias/merge inadvertently pulling in both keys.","solutions":["In the offending spring.cloud.scheduling.schedulerx.jobs.<name> block, remove either the 'cron' key or the 'oneTime' key so only one schedule type is declared.","If you need both a recurring and a one-off run, split them into two separate job entries under .jobs.","Audit all job definitions for accidental double-scheduling."],"exampleFix":"# before\nspring:\n  cloud:\n    scheduling:\n      schedulerx:\n        jobs:\n          my-job:\n            className: com.example.MyJob\n            cron: \"0 0 9 * * ?\"\n            oneTime: \"2025-01-01 00:00:00\"\n\n# after (recurring only)\nspring:\n  cloud:\n    scheduling:\n      schedulerx:\n        jobs:\n          my-job:\n            className: com.example.MyJob\n            cron: \"0 0 9 * * ?\"","handlingStrategy":"validation","validationCode":"for (Map.Entry<String, JobProperty> e : properties.getJobs().entrySet()) {\n    JobProperty j = e.getValue();\n    if (StringUtils.isNotEmpty(j.getCron()) && StringUtils.isNotEmpty(j.getOneTime())) {\n        throw new IllegalStateException(\n            \"job '\" + e.getKey() + \"' must set cron OR oneTime, not both\");\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Add a configuration validation test that asserts no job has both cron and oneTime.","Document in your project README that each job is either cron-scheduled or one-shot, never both."],"tags":["java","spring-cloud-alibaba","schedulerx","configuration","validation"],"backgroundTag":null,"analyzedSha":"115d5901102009492e05d5ec18c3f79cad4077d0","analyzedAt":"2026-08-14T04:47:13.900Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}