{"record":{"id":"c98001ac611d6ba9","repo":"pentaho/pentaho-kettle","slug":"unknown-date-string-date-string-is-null","errorCode":null,"errorMessage":"Unknown date string. Date string is null. ","messagePattern":"Unknown date string\\. Date string is null\\. ","errorType":"exception","errorClass":"ParseException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/pentaho/di/core/util/DateDetector.java","lineNumber":245,"sourceCode":"    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 );\n  }\n\n  /**","sourceCodeStart":227,"sourceCodeEnd":263,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/core/util/DateDetector.java#L227-L263","documentation":"DateDetector.getDateFromStringByFormat also validates the date string itself: if dateString is null, a ParseException 'Unknown date string. Date string is null.' is thrown. The non-lenient parser would otherwise NPE or misbehave, so this gives an explicit, checkable error.","triggerScenarios":"Calling getDateFromStringByFormat(null, format), e.g. when the upstream field was absent in a row, a CSV column was missing, or a variable did not resolve.","commonSituations":"Optional date columns in input files; rows with empty/missing fields reaching date conversion; unresolvable Kettle environment variables.","solutions":["Null-check the input string before parsing and skip/default the field","Treat empty strings as null and handle explicitly before conversion","Coalesce with a default date when the field is legitimately optional"],"exampleFix":"// before\nDate d = DateDetector.getDateFromStringByFormat(row.getString(\"dt\"), fmt);\n// after\nString s = row.getString(\"dt\");\nDate d = (s == null || s.isEmpty()) ? null : DateDetector.getDateFromStringByFormat(s, fmt);","handlingStrategy":"validation","validationCode":"if (dateString == null || dateString.trim().isEmpty()) { return null; /* optional field */ }","typeGuard":"static boolean isPresent(String s) { return s != null && !s.trim().isEmpty(); }","tryCatchPattern":"try {\n  return DateDetector.getDateFromStringByFormat(s, fmt);\n} catch (ParseException e) {\n  if (s == null) return null; // treat as missing\n  throw e;\n}","preventionTips":["Null-check/trim row fields before date conversion","Define null-handling policy per field in the transformation","Use ISNULL checks in the pipeline before the date step"],"tags":["date","parsing","null"],"backgroundTag":"null-argument","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"}