{"record":{"id":"2ef0605483b0a57d","repo":"apache/hadoop","slug":"unable-to-parse-relative-time-value-of-too-sho","errorCode":null,"errorMessage":"Unable to parse relative time value of {}: too short","messagePattern":"Unable to parse relative time value of (.+?): too short","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSUtil.java","lineNumber":1682,"sourceCode":"   * Converts a Date into an ISO-8601 formatted datetime string.\n   */\n  public static String dateToIso8601String(Date date) {\n    return DFSUtilClient.dateToIso8601String(date);\n  }\n\n  /**\n   * Converts a time duration in milliseconds into DDD:HH:MM:SS format.\n   */\n  public static String durationToString(long durationMs) {\n    return DFSUtilClient.durationToString(durationMs);\n  }\n\n  /**\n   * Converts a relative time string into a duration in milliseconds.\n   */\n  public static long parseRelativeTime(String relTime) throws IOException {\n    if (relTime.length() < 2) {\n      throw new IOException(\"Unable to parse relative time value of \" + relTime\n          + \": too short\");\n    }\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;","sourceCodeStart":1664,"sourceCodeEnd":1700,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSUtil.java#L1664-L1700","documentation":"DFSUtil.parseRelativeTime converts relative time strings ('<number><unit>' with unit s/m/h/d, e.g. '30s', '7d') into milliseconds. A string shorter than two characters cannot contain both a number and a unit, so it fails immediately with 'too short'.","triggerScenarios":"Passing a 0- or 1-character TTL string, e.g. '5' or 's'. Real call sites are CacheAdmin's -ttl option (CacheAdmin.java:107) and AdminHelper's max-ttl parsing (AdminHelper.java:108), i.e. `hdfs cacheadmin -addDirective -ttl 5`.","commonSituations":"Forgetting the unit suffix on cache directive TTL arguments; scripts that trim or truncate the last character; empty values passed through from pipelines.","solutions":["Pass at least two characters: digits followed by a unit suffix s, m, h or d (e.g. 5s, 10m, 12h, 7d)","If a bare number was intended as seconds, append 's' (5 -> 5s)"],"exampleFix":"// before\nhdfs cacheadmin -addDirective -path /data -pool mypool -ttl 5\n// after\nhdfs cacheadmin -addDirective -path /data -pool mypool -ttl 5s","handlingStrategy":"validation","validationCode":"static boolean isParsableRelativeTime(String s) {\n  return s != null && s.length() >= 2;\n}","typeGuard":null,"tryCatchPattern":"catch (IOException e) around DFSUtil.parseRelativeTime / cacheadmin TTL handling and re-prompt the user for input in CLI tools; do not retry the same string.","preventionTips":["In CLI wrappers, validate TTL args before invoking cacheadmin","Document the <number><s|m|h|d> format next to every -ttl option"],"tags":["hdfs","cli","parsing","duration","ttl","cacheadmin"],"backgroundTag":"invalid-duration-format","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}