{"record":{"id":"8c8488c13bb405f4","repo":"alibaba/spring-cloud-alibaba","slug":"cronexpression-cannot-be-null","errorCode":null,"errorMessage":"cronExpression cannot be null","messagePattern":"cronExpression cannot be null","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-schedulerx/src/main/java/com/alibaba/cloud/scheduling/schedulerx/util/CronExpression.java","lineNumber":125,"sourceCode":"\t}\n\n\t/**\n\t * MIN_DATE.\n\t */\n\tpublic static final Date MIN_DATE = MIN_CAL.getTime();\n\n\t/**\n\t * Constructs a new <CODE>CronExpression</CODE> based on the specified\n\t * parameter.\n\t *\n\t * @param cronExpression String representation of the cron expression the\n\t *                       new object should represent\n\t * @throws ParseException if the string expression cannot be parsed into a valid\n\t *                        <CODE>CronExpression</CODE>\n\t */\n\tpublic CronExpression(final String cronExpression) throws ParseException {\n\t\tif (cronExpression == null) {\n\t\t\tthrow new IllegalArgumentException(\"cronExpression cannot be null\");\n\t\t}\n\n\t\tthis.cronExpression = cronExpression.toUpperCase(Locale.US);\n\n\t\tbuildExpression(this.cronExpression);\n\t}\n\n\t/**\n\t * Indicates whether the given date satisfies the cron expression. Note that\n\t * milliseconds are ignored, so two Dates falling on different milliseconds\n\t * of the same second will always have the same result here.\n\t *\n\t * @param date the date to evaluate\n\t * @return a boolean indicating whether the given date satisfies the cron\n\t * expression.\n\t */\n\tpublic boolean isSatisfiedBy(final Date date) {\n\t\tfinal Calendar testDateCal = Calendar.getInstance(getTimeZone());","sourceCodeStart":107,"sourceCodeEnd":143,"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/util/CronExpression.java#L107-L143","documentation":"Thrown by the CronExpression(String) constructor when the argument is null. This is an IllegalArgumentException (not ParseException) fired before any parsing, guarding the field cronExpression.toUpperCase(Locale.US) from an NPE. CronExpression is a port of the Quartz cron parser used by the schedulerx starter to interpret job cron fields.","triggerScenarios":"new CronExpression(null) — i.e. the constructor is invoked with a null String. Within the starter the call sites guard with 'cron != null && !cron.isEmpty()', so this surfaces mainly when CronExpression is used directly or when a future change skips the guard.","commonSituations":"Direct unit testing of CronExpression passing null; a custom integration that reads a cron from a nullable source and constructs CronExpression without a null check; reflection or deserialization producing a null cron.","solutions":["Ensure the String passed to new CronExpression(...) is non-null before construction.","If the cron source may legitimately be null (no schedule), branch on nullability and skip construction.","In starter config, leave the cron key absent rather than setting it to a null-valued placeholder."],"exampleFix":"// before\nCronExpression expr = new CronExpression(maybeNullCron);\n\n// after\nif (maybeNullCron == null) {\n    throw new IllegalArgumentException(\"cron expression must not be null\");\n}\nCronExpression expr = new CronExpression(maybeNullCron);","handlingStrategy":"type-guard","validationCode":"java.util.Objects.requireNonNull(cron, \"cron expression must not be null\");\n// then: new CronExpression(cron)","typeGuard":"// type guard / narrowing helper\nstatic CronExpression safeCron(String cron) throws ParseException {\n    if (cron == null || cron.isEmpty()) {\n        throw new IllegalArgumentException(\"cron must be non-empty\");\n    }\n    return new CronExpression(cron);\n}","tryCatchPattern":null,"preventionTips":["Never pass a @Nullable cron to CronExpression; gate construction behind a null/empty check.","Annotate the consuming method parameter with @NonNull and let static analysis (Checker/Spotbugs) flag null callers."],"tags":["java","schedulerx","cron","null-safety"],"backgroundTag":null,"analyzedSha":"115d5901102009492e05d5ec18c3f79cad4077d0","analyzedAt":"2026-08-14T04:47:13.900Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}