apache/hadoop · error · IOException

Unable to parse relative time value of {}: too short

Error message

Unable to parse relative time value of {}: too short

What it means

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'.

Source

Thrown at hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSUtil.java:1682

   * Converts a Date into an ISO-8601 formatted datetime string.
   */
  public static String dateToIso8601String(Date date) {
    return DFSUtilClient.dateToIso8601String(date);
  }

  /**
   * Converts a time duration in milliseconds into DDD:HH:MM:SS format.
   */
  public static String durationToString(long durationMs) {
    return DFSUtilClient.durationToString(durationMs);
  }

  /**
   * Converts a relative time string into a duration in milliseconds.
   */
  public static long parseRelativeTime(String relTime) throws IOException {
    if (relTime.length() < 2) {
      throw new IOException("Unable to parse relative time value of " + relTime
          + ": too short");
    }
    String ttlString = relTime.substring(0, relTime.length()-1);
    long ttl;
    try {
      ttl = Long.parseLong(ttlString);
    } catch (NumberFormatException e) {
      throw new IOException("Unable to parse relative time value of " + relTime
          + ": " + ttlString + " is not a number");
    }
    if (relTime.endsWith("s")) {
      // pass
    } else if (relTime.endsWith("m")) {
      ttl *= 60;
    } else if (relTime.endsWith("h")) {
      ttl *= 60*60;
    } else if (relTime.endsWith("d")) {
      ttl *= 60*60*24;

View on GitHub (pinned to 2add963021)

Solutions

  1. Pass at least two characters: digits followed by a unit suffix s, m, h or d (e.g. 5s, 10m, 12h, 7d)
  2. If a bare number was intended as seconds, append 's' (5 -> 5s)

Example fix

// before
hdfs cacheadmin -addDirective -path /data -pool mypool -ttl 5
// after
hdfs cacheadmin -addDirective -path /data -pool mypool -ttl 5s
Defensive patterns

Strategy: validation

Validate before calling

static boolean isParsableRelativeTime(String s) {
  return s != null && s.length() >= 2;
}

Try / catch

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.

Prevention

When it happens

Trigger: 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`.

Common situations: Forgetting the unit suffix on cache directive TTL arguments; scripts that trim or truncate the last character; empty values passed through from pipelines.

Understand the failure class

Related errors


AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22). Data as JSON: /api/errors/2ef0605483b0a57d. Report an issue: GitHub.