{"record":{"id":"b94728ab61fde752","repo":"zhisheng17/flink-learning","slug":"time-interval-unit-unit-does-not-match-any-of","errorCode":null,"errorMessage":"Time interval unit '${unit}' does not match any of the recognized units: ${TimeUnit.getAllUnits()}","messagePattern":"Time interval unit '(.+?)' does not match any of the recognized units: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"flink-learning-core/src/main/java/com/zhisheng/core/utils/TimeUtils.java","lineNumber":80,"sourceCode":"\t\t} catch (NumberFormatException e) {\n\t\t\tthrow new IllegalArgumentException(\"The value '\" + number +\n\t\t\t\t\"' cannot be re represented as 64bit number (numeric overflow).\");\n\t\t}\n\n\t\tfinal long multiplier;\n\t\tif (unit.isEmpty()) {\n\t\t\tmultiplier = 1L;\n\t\t} else {\n\t\t\tif (matchTimeUnit(unit, TimeUnit.MILLISECONDS)) {\n\t\t\t\tmultiplier = 1L;\n\t\t\t} else if (matchTimeUnit(unit, TimeUnit.SECONDS)) {\n\t\t\t\tmultiplier = 1000L;\n\t\t\t} else if (matchTimeUnit(unit, TimeUnit.MINUTES)) {\n\t\t\t\tmultiplier = 1000L * 60L;\n\t\t\t} else if (matchTimeUnit(unit, TimeUnit.HOURS)) {\n\t\t\t\tmultiplier = 1000L * 60L * 60L;\n\t\t\t} else {\n\t\t\t\tthrow new IllegalArgumentException(\"Time interval unit '\" + unit +\n\t\t\t\t\t\"' does not match any of the recognized units: \" + TimeUnit.getAllUnits());\n\t\t\t}\n\t\t}\n\n\t\tfinal long result = value * multiplier;\n\n\t\t// check for overflow\n\t\tif (result / multiplier != value) {\n\t\t\tthrow new IllegalArgumentException(\"The value '\" + text +\n\t\t\t\t\"' cannot be re represented as 64bit number of bytes (numeric overflow).\");\n\t\t}\n\n\t\treturn Duration.ofMillis(result);\n\t}\n\n\tprivate static boolean matchTimeUnit(String text, TimeUnit unit) {\n\t\treturn text.equals(unit.getUnit());\n\t}","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/zhisheng17/flink-learning/blob/d731cee7618021be56d132cc925102ffff8d75e6/flink-learning-core/src/main/java/com/zhisheng/core/utils/TimeUtils.java#L62-L98","documentation":"TimeUtils.parseDuration parses human-readable duration strings like '100 ms' or '5 s'. It throws this IllegalArgumentException when the unit token after the numeric value does not match any recognized time unit (ms, s, m, min, h, d etc.) as checked by matchTimeUnit against TimeUnit constants.","triggerScenarios":"Calling TimeUtils.parseDuration with a string whose unit suffix matches no known unit, e.g. '30sec', '5 minutes ' with stray characters, '10msx', or an empty unit after the number.","commonSituations":"Typo in Flink config values like 'task.cancellation-interval: 10secs'; locale/case mismatches; copy-pasted config from docs of another framework with different unit abbreviations.","solutions":["Fix the duration string to use a recognized unit: '100 ms', '5 s', '10 min', '2 h', '1 d'.","Check TimeUtils/matchTimeUnit for the exact accepted unit spellings (they accept common prefixes/suffixes of TimeUnit).","If parsing user input, pre-validate the unit against the accepted set and produce a friendlier message.","Fall back to plain numeric values (interpreted as milliseconds) where the config allows it."],"exampleFix":"// before\nTimeUtils.parseDuration(\"30secs\");\n// after\nTimeUtils.parseDuration(\"30 s\");","handlingStrategy":"validation","validationCode":"private static final java.util.regex.Pattern DURATION = java.util.regex.Pattern.compile(\"^\\\\s*\\\\d+\\\\s*(ms|s|m|min|h|d)\\\\s*$\");\nstatic void checkDuration(String text) {\n    if (text == null || !DURATION.matcher(text).matches())\n        throw new IllegalArgumentException(\"Unrecognized duration: \" + text);\n}","typeGuard":null,"tryCatchPattern":"try {\n    Duration d = TimeUtils.parseDuration(cfg.get(\"interval\"));\n} catch (IllegalArgumentException e) {\n    log.warn(\"Bad duration '{}', falling back to 1s\", cfg.get(\"interval\"), e);\n    d = Duration.ofSeconds(1);\n}","preventionTips":["Only use units accepted by TimeUtils (ms, s, m/min, h, d)","Trim whitespace and validate duration strings before parsing","Centralize duration parsing in one config helper with pre-validation","Prefer plain milliseconds in config when unit syntax is uncertain"],"tags":["duration","parsing","config"],"backgroundTag":"invalid-duration-format","analyzedSha":"d731cee7618021be56d132cc925102ffff8d75e6","analyzedAt":"2026-09-06T05:35:08.496Z","contentChangedAt":"2026-09-06T05:35:08.496Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}