{"record":{"id":"594b92852f2a4673","repo":"pentaho/pentaho-kettle","slug":"unknown-date-format-format-is-null","errorCode":null,"errorMessage":"Unknown date format. Format is null. ","messagePattern":"Unknown date format\\. Format is null\\. ","errorType":"exception","errorClass":"ParseException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/pentaho/di/core/util/DateDetector.java","lineNumber":242,"sourceCode":"    if ( dateFormat == null ) {\n      throw new ParseException( \"Unknown date format.\", 0 );\n    }\n    return getDateFromStringByFormat( dateString, dateFormat );\n  }\n\n  /**\n   * \n   * @param dateString\n   *          date string for parse\n   * @param dateFormat\n   *          format which should be applied for string\n   * @return {@link java.util.Date} converted from dateString by format\n   * @throws ParseException\n   *           if we can not parse date string\n   */\n  public static Date getDateFromStringByFormat( String dateString, String dateFormat ) throws ParseException {\n    if ( dateFormat == null ) {\n      throw new ParseException( \"Unknown date format. Format is null. \", 0 );\n    }\n    if ( dateString == null ) {\n      throw new ParseException( \"Unknown date string. Date string is null. \", 0 );\n    }\n    SimpleDateFormat simpleDateFormat = new SimpleDateFormat( dateFormat );\n    simpleDateFormat.setLenient( false ); // Don't automatically convert invalid date.\n    return simpleDateFormat.parse( dateString );\n  }\n\n  /**\n   * \n   * @param dateString\n   *          - date string for detect date format\n   * @return {@link java.lang.String} string which represented Date Format or null\n   * \n   */\n  public static String detectDateFormat( String dateString ) {\n    return detectDateFormat( dateString, null );","sourceCodeStart":224,"sourceCodeEnd":260,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/core/util/DateDetector.java#L224-L260","documentation":"DateDetector.getDateFromStringByFormat parses a date string with a caller-supplied format using a non-lenient SimpleDateFormat. If the dateFormat argument is null, a ParseException 'Unknown date format. Format is null.' is thrown immediately, because a null pattern cannot construct a formatter.","triggerScenarios":"Passing a null format, typically the result of detectDateFormat returning null that was forwarded without checking, or a config variable that failed to resolve.","commonSituations":"Chaining detectDateFormat() -> getDateFromStringByFormat() without a null check; date format read from missing properties/settings.","solutions":["Null-check the format before calling; fall back to detectDateFormat or a default pattern","Hard-code or validate the expected format string at configuration time","Use getDateFromString (auto-detect) when format is unknown instead of passing null"],"exampleFix":"// before\nDate d = DateDetector.getDateFromStringByFormat(s, maybeNullFormat);\n// after\nif (maybeNullFormat == null) { maybeNullFormat = DateDetector.detectDateFormat(s); }\nDate d = DateDetector.getDateFromStringByFormat(s, maybeNullFormat);","handlingStrategy":"validation","validationCode":"if (dateFormat == null) { dateFormat = \"yyyy-MM-dd\"; } // or resolve via detectDateFormat\nif (dateString == null) { throw new IllegalArgumentException(\"dateString required\"); }","typeGuard":null,"tryCatchPattern":"try {\n  return DateDetector.getDateFromStringByFormat(s, fmt);\n} catch (ParseException e) {\n  LOG.error(\"Bad format '{}' or value '{}'\", fmt, s, e);\n  throw e;\n}","preventionTips":["Never forward detectDateFormat results without a null check","Load date formats from validated configuration with defaults","Fail fast at config-load time when the format key is missing"],"tags":["date","parsing","null"],"backgroundTag":"invalid-date-format","analyzedSha":"f3058517a153da500bf4551f46d79b91bf8ec552","analyzedAt":"2026-09-13T14:04:16.340Z","contentChangedAt":"2026-09-13T14:04:16.340Z","schemaVersion":2},"datasetVersion":"2026-09-20T23:17:15.980Z"}