{"record":{"id":"989a08d8170f05f2","repo":"MyCATApache/Mycat-Server","slug":"invalid-suffix-suffix","errorCode":null,"errorMessage":"Invalid suffix: \"${suffix}\"","messagePattern":"Invalid suffix: \"(.+?)\"","errorType":"validation","errorClass":"NumberFormatException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/memory/unsafe/utils/JavaUtils.java","lineNumber":159,"sourceCode":"  /**\n   * Convert a passed time string (e.g. 50s, 100ms, or 250us) to a time count in the given unit.\n   * The unit is also considered the default if the given string does not specify a unit.\n   */\n  public static long timeStringAs(String str, TimeUnit unit) {\n    String lower = str.toLowerCase().trim();\n\n    try {\n      Matcher m = Pattern.compile(\"(-?[0-9]+)([a-z]+)?\").matcher(lower);\n      if (!m.matches()) {\n        throw new NumberFormatException(\"Failed to parse time string: \" + str);\n      }\n\n      long val = Long.parseLong(m.group(1));\n      String suffix = m.group(2);\n\n      // Check for invalid suffixes\n      if (suffix != null && !timeSuffixes.containsKey(suffix)) {\n        throw new NumberFormatException(\"Invalid suffix: \\\"\" + suffix + \"\\\"\");\n      }\n\n      // If suffix is valid use that, otherwise none was provided and use the default passed\n      return unit.convert(val, suffix != null ? timeSuffixes.get(suffix) : unit);\n    } catch (NumberFormatException e) {\n      String timeError = \"Time must be specified as seconds (s), \" +\n              \"milliseconds (ms), microseconds (us), minutes (m or min), hour (h), or day (d). \" +\n              \"E.g. 50s, 100ms, or 250us.\";\n\n      throw new NumberFormatException(timeError + \"\\n\" + e.getMessage());\n    }\n  }\n\n  /**\n   * Convert a time parameter such as (50s, 100ms, or 250us) to milliseconds for internal use. If\n   * no suffix is provided, the passed number is assumed to be in ms.\n   */\n  public static long timeStringAsMs(String str) {","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/memory/unsafe/utils/JavaUtils.java#L141-L177","documentation":"Thrown by JavaUtils.timeStringAs while converting a duration string (e.g. '50s', '100ms', '250us') to a count in the requested TimeUnit. After the numeric part parses, the optional unit suffix is looked up in a suffix-to-TimeUnit map; if the suffix is unrecognized (or required and absent), a NumberFormatException with this message is raised. It is a configuration-value validation error: the at-fault input is the string suffix embedded in a time configuration value. Use supported suffixes (ns/us/ms/s/m/h/d) or omit the suffix to take the default unit.","triggerScenarios":"Passing values like \"50sec\", \"5milliseconds\", \"2w\", \"30min\" (if min unsupported here — it is supported; e.g. \"30mins\"), or \"1H\" is fine due to lowercase but \"1 seconds\" fails at regex stage; specifically any letters after the number that aren't a known suffix.","commonSituations":"Writing durations in units the parser doesn't know (weeks, seconds spelled 'sec', 'hrs'); copying config from another system with different duration conventions.","solutions":["Rewrite the value using supported suffixes: s, ms, us, m or min, h, d.","Convert unsupported units explicitly (e.g. 2w → 14d).","Check the exception message: the wrapping error (186) repeats the accepted units."],"exampleFix":"// before\nlong ms = JavaUtils.timeStringAsMs(\"5sec\");\n// after\nlong ms = JavaUtils.timeStringAsMs(\"5s\");","handlingStrategy":"validation","validationCode":"static boolean isValidTimeSuffix(String s) {\n  java.util.regex.Matcher m = java.util.regex.Pattern.compile(\"-?[0-9]+([a-z]+)?\").matcher(s.trim().toLowerCase());\n  return m.matches() && (m.group(1) == null || java.util.Arrays.asList(\"s\",\"ms\",\"us\",\"m\",\"min\",\"h\",\"d\").contains(m.group(1)));\n}","typeGuard":null,"tryCatchPattern":"try {\n  long ms = JavaUtils.timeStringAsMs(raw);\n} catch (NumberFormatException e) {\n  ms = defaultMillis;\n}","preventionTips":["Only use documented suffixes: s, ms, us, m or min, h, d.","Translate foreign unit conventions (sec, msec, w) before parsing.","Share a single normalizeDuration() helper across your config layer."],"tags":["java","parsing","configuration","duration"],"backgroundTag":"invalid-duration-format","analyzedSha":"65f8d8beb752f935752f2a0eec0ab017facab9ef","analyzedAt":"2026-09-11T00:12:21.696Z","contentChangedAt":"2026-09-11T00:12:21.696Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}