{"record":{"id":"09d405ec99bd2302","repo":"apache/hadoop","slug":"unable-to-parse-relative-time-value-of-is-n","errorCode":null,"errorMessage":"Unable to parse relative time value of {}: {} is not a number","messagePattern":"Unable to parse relative time value of (.+?): (.+?) is not a number","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSUtil.java","lineNumber":1690,"sourceCode":"   */\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;\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  /**","sourceCodeStart":1672,"sourceCodeEnd":1708,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSUtil.java#L1672-L1708","documentation":"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.","triggerScenarios":"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.","commonSituations":"Typos and mixed units in TTL arguments ('10d5'); negative or symbolic values like '-1s', 'onem'; copy-paste from docs with typographic characters.","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"],"exampleFix":"// before\nhdfs cacheadmin -addDirective -ttl 10d5\n// after\nhdfs cacheadmin -addDirective -ttl 252h","handlingStrategy":"validation","validationCode":"static boolean isParsableRelativeTime(String s) {\n  return s != null && s.matches(\"\\\\d+[smhd]\");\n}","typeGuard":null,"tryCatchPattern":"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.","preventionTips":["Validate TTL input with regex ^\\d+[smhd]$ before calling parseRelativeTime","Reject symbolic or negative values early in argument parsing"],"tags":["hdfs","cli","parsing","duration","ttl","number-format"],"backgroundTag":"invalid-duration-format","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}