apache/hadoop · error · IOException
Unable to parse relative time value of {}: {} is not a numbe
Error message
Unable to parse relative time value of {}: {} is not a number What it means
DFSUtil.parseRelativeTime strips the last character as the unit and requires the remainder to be a long. If Long.parseLong fails on the prefix, it throws 'X is not a number'. The prefix must be pure digits.
Source
Thrown at hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSUtil.java:1690
*/
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;
} else {
throw new IOException("Unable to parse relative time value of " + relTime
+ ": unknown time unit " + relTime.charAt(relTime.length() - 1));
}
return ttl*1000;
}
/**View on GitHub (pinned to 2add963021)
Solutions
- Use only decimal digits before the unit: 30s, 10m, 12h, 7d
- For compound durations, precompute a single value (e.g. 1d12h -> 36h)
- Remove stray characters/symbols from the value
Example fix
// before hdfs cacheadmin -addDirective -ttl 10d5 // after hdfs cacheadmin -addDirective -ttl 252h
Defensive patterns
Strategy: validation
Validate before calling
static boolean isParsableRelativeTime(String s) {
return s != null && s.matches("\\d+[smhd]");
} Try / catch
catch (IOException e) around DFSUtil.parseRelativeTime; on 'is not a number' reject the input at the CLI boundary and ask for digits + unit rather than propagating.
Prevention
- Validate TTL input with regex ^\d+[smhd]$ before calling parseRelativeTime
- Reject symbolic or negative values early in argument parsing
When it happens
Trigger: TTL strings whose leading part is non-numeric or contains extra characters: 'xs' (prefix 'x'), '-s' (prefix '-'), '1s2m' (prefix '1s2'), or empty prefix variants like 's'. Hit via `hdfs cacheadmin -addDirective -ttl` or AdminHelper max-ttl parsing.
Common situations: Typos and mixed units in TTL arguments ('10d5'); negative or symbolic values like '-1s', 'onem'; copy-paste from docs with typographic characters.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Unable to parse relative time value of {}: too short
- Unable to parse relative time value of {}: unknown time unit
- "{}" is not a valid value for a quota.
- Cannot parse nsQuota: {}
- Cannot parse ssQuota: {}
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/09d405ec99bd2302.
Report an issue: GitHub.