{"record":{"id":"8ec88139e44a9a88","repo":"apache/dolphinscheduler","slug":"the-date-must-not-be-null","errorCode":null,"errorMessage":"The date must not be null","messagePattern":"The date must not be null","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/DateUtils.java","lineNumber":547,"sourceCode":"     * get current date\n     *\n     * @return current date\n     */\n    public static Date getCurrentDate() {\n        return new Date();\n    }\n\n    /**\n     * get date\n     *\n     * @param date          date\n     * @param calendarField calendarField\n     * @param amount        amount\n     * @return date\n     */\n    public static Date add(final Date date, final int calendarField, final int amount) {\n        if (date == null) {\n            throw new IllegalArgumentException(\"The date must not be null\");\n        }\n        final Calendar c = Calendar.getInstance();\n        c.setTime(date);\n        c.add(calendarField, amount);\n        return c.getTime();\n    }\n\n    /**\n     * starting from the current time, get how many seconds are left before the target time.\n     * targetTime = baseTime + intervalSeconds\n     *\n     * @param baseTime        base time\n     * @param intervalSeconds a period of time\n     * @return the number of seconds\n     */\n    public static long getRemainTime(Date baseTime, long intervalSeconds) {\n        if (baseTime == null) {\n            return 0;","sourceCodeStart":529,"sourceCodeEnd":565,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/DateUtils.java#L529-L565","documentation":"DateUtils.add is a null-safe guard around java.util.Calendar date arithmetic (a commons-lang style utility). It throws IllegalArgumentException(\"The date must not be null\") when the date argument is null, before creating a Calendar and applying the calendarField/amount adjustment.","triggerScenarios":"Calling add(date, field, amount) with a null Date — directly, or indirectly via the convenience wrappers addMonths, addDays, or addMinutes, which forward their date argument unchanged.","commonSituations":"Computing schedule/timeout times from a nullable upstream value (e.g. a process instance end time that is null for still-running instances); DB column being NULL so the mapped Date is null; calling addMinutes(new Date()) with a typo'd variable that is uninitialized/null.","solutions":["Check the date for null before calling and use a sensible default (e.g. new Date() or a fixed epoch)","Trace the caller (addMonths/addDays/addMinutes) to find which upstream value is null and fix it at the source (e.g. handle the 'not yet finished' case explicitly)","If null means 'not applicable', skip the date computation rather than defaulting","When the value comes from a DB/entity field, make the column NOT NULL or use Optional at the mapping layer"],"exampleFix":"// before\nDate deadline = DateUtils.addMinutes(endTime, 30); // NPE-ish IAE when endTime == null\n\n// after\nDate deadline = endTime != null\n        ? DateUtils.addMinutes(endTime, 30)\n        : DateUtils.addMinutes(new Date(), 30);","handlingStrategy":"type-guard","validationCode":"if (date == null) {\n    throw new IllegalArgumentException(\"endTime must be set before computing deadline\");\n}","typeGuard":"static Date requireDate(Date d) {\n    if (d == null) throw new IllegalArgumentException(\"The date must not be null\");\n    return d;\n}\n// usage: DateUtils.addMinutes(requireDate(endTime), 30)","tryCatchPattern":"try {\n    Date later = DateUtils.addDays(date, 1);\n} catch (IllegalArgumentException e) {\n    if (\"The date must not be null\".equals(e.getMessage())) {\n        log.warn(\"Skipping date computation: source date is null\");\n    } else throw e;\n}","preventionTips":["Null-check dates from nullable entity fields (e.g. unfinished instance end times) before arithmetic","Use Optional<Date> at the API boundary for nullable timestamps","Enforce NOT NULL on DB columns that feed date math","Wrap addMonths/addDays/addMinutes calls in helpers that apply defaults"],"tags":["date","null","illegal-argument","date-arithmetic"],"backgroundTag":"null-argument","analyzedSha":"02eac45a1b6676e639fcbfb4be2243de5771b05d","analyzedAt":"2026-09-06T17:43:00.555Z","contentChangedAt":"2026-09-06T17:43:00.555Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}