{"record":{"id":"1beef93b4c2ef626","repo":"alibaba/nacos","slug":"date-must-not-be-null","errorCode":null,"errorMessage":"date must not be null","messagePattern":"date must not be null","errorType":"validation","errorClass":"NullPointerException","httpStatus":null,"severity":"warning","filePath":"common/src/main/java/com/alibaba/nacos/common/utils/DateFormatUtils.java","lineNumber":60,"sourceCode":"    \n    public static final String MM = \"MM\";\n    \n    public static final String DD = \"dd\";\n    \n    public static final String YYYYMMDDSLASH = \"yyyy/MM/dd\";\n    \n    public static final String YYYYMMDDHHMMSSNOMARK = \"yyyyMMddHHmmss\";\n    \n    /**\n     * Formats a date/time into a specific pattern.\n     *\n     * @param date  the date to format, not null\n     * @param pattern  the pattern to use to format the date, not null\n     * @return the formatted date\n     */\n    public static String format(final Date date, final String pattern) {\n        if (date == null) {\n            throw new NullPointerException(\"date must not be null\");\n        }\n        if (pattern == null) {\n            throw new NullPointerException(\"pattern must not be null\");\n        }\n        SimpleDateFormat sdf = new SimpleDateFormat(pattern);\n        return sdf.format(date);\n    }\n    \n}\n","sourceCodeStart":42,"sourceCodeEnd":70,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/common/src/main/java/com/alibaba/nacos/common/utils/DateFormatUtils.java#L42-L70","documentation":"Thrown by DateFormatUtils.format(Date, String) when the date argument is null. The method explicitly checks and throws NullPointerException (not IllegalArgumentException). The Javadoc declares both date and pattern must be non-null.","triggerScenarios":"Calling DateFormatUtils.format(nullDate, pattern) where nullDate is a Date that was never assigned (e.g., a parsed date that failed to populate, a DB column that was null).","commonSituations":"A nullable timestamp field from a database row or external payload passed straight to format(); a date parse upstream that returned null on failure and was not checked.","solutions":["Null-check the Date before formatting.","Fix the upstream source so the Date is never null (require it, or default to a sentinel).","Return a default formatted string or skip formatting when the date is absent."],"exampleFix":"// before\nString s = DateFormatUtils.format(maybeNullDate, DateFormatUtils.YYYYMMDDHHMMSSNOMARK);\n\n// after\nString s = maybeNullDate == null ? null : DateFormatUtils.format(maybeNullDate, DateFormatUtils.YYYYMMDDHHMMSSNOMARK);","handlingStrategy":"validation","validationCode":"if (date == null) {\n    return null; // or throw domain error\n}\nreturn DateFormatUtils.format(date, pattern);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Null-check Date inputs before formatting.","Require dates at the data source rather than letting null propagate."],"tags":["date","null-check","formatting","utility"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}