{"record":{"id":"7836c20ea637dde2","repo":"zhisheng17/flink-learning","slug":"text-does-not-start-with-a-number","errorCode":null,"errorMessage":"text does not start with a number","messagePattern":"text does not start with a number","errorType":"validation","errorClass":"NumberFormatException","httpStatus":null,"severity":"error","filePath":"flink-learning-core/src/main/java/com/zhisheng/core/utils/TimeUtils.java","lineNumber":56,"sourceCode":"\tpublic static Duration parseDuration(String text) {\n\t\tcheckNotNull(text, \"text\");\n\n\t\tfinal String trimmed = text.trim();\n\t\tcheckArgument(!trimmed.isEmpty(), \"argument is an empty- or whitespace-only string\");\n\n\t\tfinal int len = trimmed.length();\n\t\tint pos = 0;\n\n\t\tchar current;\n\t\twhile (pos < len && (current = trimmed.charAt(pos)) >= '0' && current <= '9') {\n\t\t\tpos++;\n\t\t}\n\n\t\tfinal String number = trimmed.substring(0, pos);\n\t\tfinal String unit = trimmed.substring(pos).trim().toLowerCase(Locale.US);\n\n\t\tif (number.isEmpty()) {\n\t\t\tthrow new NumberFormatException(\"text does not start with a number\");\n\t\t}\n\n\t\tfinal long value;\n\t\ttry {\n\t\t\tvalue = Long.parseLong(number); // this throws a NumberFormatException on overflow\n\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;","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/zhisheng17/flink-learning/blob/d731cee7618021be56d132cc925102ffff8d75e6/flink-learning-core/src/main/java/com/zhisheng/core/utils/TimeUtils.java#L38-L74","documentation":"TimeUtils.parseDuration parses strings like '100 ms' or '5 s' into milliseconds. It splits the numeric prefix from the unit suffix; if the text begins with the unit and has no leading number (number.isEmpty()), it throws NumberFormatException('text does not start with a number').","triggerScenarios":"Calling parseDuration with input such as 'ms', ' s', 'seconds', or any string where the first non-whitespace characters are not digits/sign — the first whitespace-split token is not numeric.","commonSituations":"Config values written as 'seconds' instead of '5 seconds', units-only typo, empty-ish strings like '-' or non-numeric prefixes in duration settings.","solutions":["Provide a numeric value with the unit, e.g. '5 s' or '100 ms'","Validate the duration string matches a number-then-unit pattern before parsing","Trim and correct the config value; use a plain integer (e.g. '500') if the unit is optional in your context"],"exampleFix":"// before\nTimeUtils.parseDuration(\"seconds\");\n// after\nTimeUtils.parseDuration(\"5 seconds\");","handlingStrategy":"validation","validationCode":"static boolean isParsableDuration(String text) {\n    if (text == null) return false;\n    String t = text.trim();\n    int i = 0;\n    if (i < t.length() && (t.charAt(i) == '+' || t.charAt(i) == '-')) i++;\n    return i < t.length() && Character.isDigit(t.charAt(i));\n}","typeGuard":null,"tryCatchPattern":"try {\n    long ms = TimeUtils.parseDuration(text);\n} catch (NumberFormatException e) {\n    if (\"text does not start with a number\".equals(e.getMessage())) {\n        LOG.warn(\"Duration '{}' must start with a number, e.g. '5 s'\", text);\n        ms = defaultValue;\n    } else throw e;\n}","preventionTips":["Always write durations as '<number> <unit>' (e.g. '10 s', '500 ms')","Validate config strings with a regex like ^[+-]?\\\\d+\\\\s*\\\\w*$ before parsing","Test config parsing at startup so bad values fail fast"],"tags":["java","parsing","duration","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-14T00:17:10.932Z"}