{"record":{"id":"ab5e48295683da3b","repo":"alibaba/nacos","slug":"pattern-must-not-be-null","errorCode":null,"errorMessage":"pattern must not be null","messagePattern":"pattern 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":63,"sourceCode":"    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":45,"sourceCodeEnd":70,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/common/src/main/java/com/alibaba/nacos/common/utils/DateFormatUtils.java#L45-L70","documentation":"Thrown by DateFormatUtils.format(Date, String) when the pattern argument is null. Distinct from the date-null case (790); here the date is fine but the format pattern is missing.","triggerScenarios":"Calling DateFormatUtils.format(date, nullPattern) — pattern is a nullable variable or a constant that resolved to null.","commonSituations":"A pattern sourced from configuration that was not set; a conditional that leaves the pattern null on some code path; passing a user-supplied pattern without validation.","solutions":["Validate the pattern is non-null before formatting.","Default the pattern to a known constant (e.g., DateFormatUtils.YYYYMMDDHHMMSSNOMARK).","Surface configuration errors for the missing pattern key at startup."],"exampleFix":"// before\nString s = DateFormatUtils.format(date, patternFromConfig);\n\n// after\nString pattern = patternFromConfig != null ? patternFromConfig : DateFormatUtils.YYYYMMDDHHMMSSNOMARK;\nString s = DateFormatUtils.format(date, pattern);","handlingStrategy":"validation","validationCode":"if (pattern == null) {\n    pattern = DateFormatUtils.YYYYMMDDHHMMSSNOMARK; // safe default\n}\nreturn DateFormatUtils.format(date, pattern);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate or default the pattern before formatting.","Surface missing pattern config keys at startup."],"tags":["date","null-check","formatting","configuration","utility"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}