{"record":{"id":"bec399bdb4e27412","repo":"apache/hadoop","slug":"unable-to-parse-relative-time-value-of-unknown","errorCode":null,"errorMessage":"Unable to parse relative time value of {}: unknown time unit {}","messagePattern":"Unable to parse relative time value of (.+?): unknown time unit (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSUtil.java","lineNumber":1702,"sourceCode":"    }\n    String ttlString = relTime.substring(0, relTime.length()-1);\n    long ttl;\n    try {\n      ttl = Long.parseLong(ttlString);\n    } catch (NumberFormatException e) {\n      throw new IOException(\"Unable to parse relative time value of \" + relTime\n          + \": \" + ttlString + \" is not a number\");\n    }\n    if (relTime.endsWith(\"s\")) {\n      // pass\n    } else if (relTime.endsWith(\"m\")) {\n      ttl *= 60;\n    } else if (relTime.endsWith(\"h\")) {\n      ttl *= 60*60;\n    } else if (relTime.endsWith(\"d\")) {\n      ttl *= 60*60*24;\n    } else {\n      throw new IOException(\"Unable to parse relative time value of \" + relTime\n          + \": unknown time unit \" + relTime.charAt(relTime.length() - 1));\n    }\n    return ttl*1000;\n  }\n\n  /**\n   * Load HTTPS-related configuration.\n   */\n  public static Configuration loadSslConfiguration(Configuration conf) {\n    Configuration sslConf = new Configuration(false);\n\n    sslConf.addResource(conf.get(\n        DFSConfigKeys.DFS_SERVER_HTTPS_KEYSTORE_RESOURCE_KEY,\n        DFSConfigKeys.DFS_SERVER_HTTPS_KEYSTORE_RESOURCE_DEFAULT));\n\n    final String[] reqSslProps = {\n        DFSConfigKeys.DFS_SERVER_HTTPS_TRUSTSTORE_LOCATION_KEY,\n        DFSConfigKeys.DFS_SERVER_HTTPS_KEYSTORE_LOCATION_KEY,","sourceCodeStart":1684,"sourceCodeEnd":1720,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSUtil.java#L1684-L1720","documentation":"DFSUtil.parseRelativeTime only accepts the lowercase unit suffixes s, m, h and d. If the string parses as a number but its last character is none of these, it throws 'unknown time unit <c>'. Note that a bare number like '100' lands here too, and uppercase units ('7D') are rejected because the endsWith checks are case-sensitive.","triggerScenarios":"TTL strings ending in an unsupported character: '10w', '7D', or unitless '100' (its last char '0' is treated as the unit). Reached from `hdfs cacheadmin -addDirective -ttl` and AdminHelper max-ttl parsing.","commonSituations":"Weeks ('w') or years ('y') entered as units that HDFS does not support; uppercase suffixes; bare integers without any suffix.","solutions":["Use a supported lowercase unit: s, m, h or d (e.g. 10w -> 70d or 168h)","Append a unit to bare numbers (100 -> 100s)","Lowercase the suffix (7D -> 7d)"],"exampleFix":"// before\nhdfs cacheadmin -addDirective -ttl 7D\n// after\nhdfs cacheadmin -addDirective -ttl 7d","handlingStrategy":"validation","validationCode":"import java.util.regex.*;\n\nprivate static final Pattern REL_TIME = Pattern.compile(\"^([0-9]+)([smhd])$\");\n\nstatic Long parseTtlSafely(String s) {\n  Matcher m = REL_TIME.matcher(s == null ? \"\" : s);\n  if (!m.matches()) return null; // caller reports a friendly error\n  long v = Long.parseLong(m.group(1));\n  switch (m.group(2)) {\n    case \"m\": return v * 60 * 1000;\n    case \"h\": return v * 3600 * 1000;\n    case \"d\": return v * 86400 * 1000;\n    default:  return v * 1000;\n  }\n}","typeGuard":"static boolean isParsableRelativeTime(String s) {\n  return s != null && s.matches(\"[0-9]+[smhd]\");\n}","tryCatchPattern":"catch (IOException e) around DFSUtil.parseRelativeTime; on 'unknown time unit' surface the accepted suffix list (s, m, h, d, lowercase) to the user.","preventionTips":["Remember units are lowercase-only and weeks/years are unsupported - convert w/y to d before passing","Never pass bare numbers as TTLs"],"tags":["hdfs","cli","parsing","duration","ttl","time-unit"],"backgroundTag":"invalid-duration-format","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}