{"record":{"id":"ae9db4fa9a1fc965","repo":"MyCATApache/Mycat-Server","slug":"time-must-be-specified-as-seconds-s-millisecond","errorCode":null,"errorMessage":"Time must be specified as seconds (s), milliseconds (ms), microseconds (us), minutes (m or min), hour (h), or day (d). E.g. 50s, 100ms, or 250us.\n${e.getMessage()}","messagePattern":"Time must be specified as seconds \\(s\\), milliseconds \\(ms\\), microseconds \\(us\\), minutes \\(m or min\\), hour \\(h\\), or day \\(d\\)\\. E\\.g\\. 50s, 100ms, or 250us\\.\n(.+?)","errorType":"validation","errorClass":"NumberFormatException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/memory/unsafe/utils/JavaUtils.java","lineNumber":169,"sourceCode":"        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) {\n    return timeStringAs(str, TimeUnit.MILLISECONDS);\n  }\n\n  /**\n   * Convert a time parameter such as (50s, 100ms, or 250us) to seconds for internal use. If\n   * no suffix is provided, the passed number is assumed to be in seconds.\n   */\n  public static long timeStringAsSec(String str) {\n    return timeStringAs(str, TimeUnit.SECONDS);\n  }","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/memory/unsafe/utils/JavaUtils.java#L151-L187","documentation":"This is the user-facing NumberFormatException that timeStringAs throws for ANY duration-parse failure: the message combines the accepted-units help text with the underlying error's message (bad format or bad suffix). It is the error developers actually see from timeStringAsMs/timeStringAsSec.","triggerScenarios":"Any invalid duration string reaching timeStringAs: non-matching format (\"abc\", \"1.5s\", \"\"), or unrecognized suffix (\"50sec\"). The catch block rewraps errors 184/185 with this help text.","commonSituations":"Mistyped config entries in properties/YAML; unit typos like 'sec', 'msec', 'mins+'; fractional durations; unresolved placeholders like \"${timeout}\".","solutions":["Read the nested message (after the newline) for the precise cause: format mismatch vs invalid suffix.","Fix the value to the documented format: signed integer plus optional s/ms/us/m/min/h/d suffix, e.g. 50s, 100ms, 250us.","Wrap calls with a default if config may be missing or malformed."],"exampleFix":"// before\nlong sec = JavaUtils.timeStringAsSec(props.getProperty(\"interval\")); // \"0.5min\"\n// after\nString raw = props.getProperty(\"interval\", \"30s\");\nlong sec = JavaUtils.timeStringAsSec(raw.matches(\"-?\\\\d+[a-z]*\") ? raw : \"30s\");","handlingStrategy":"try-catch","validationCode":"if (raw == null || !raw.trim().toLowerCase().matches(\"-?[0-9]+([a-z]+)?\")) {\n  raw = \"30s\"; // safe default\n}","typeGuard":null,"tryCatchPattern":"long ms;\ntry {\n  ms = JavaUtils.timeStringAsMs(raw);\n} catch (NumberFormatException e) {\n  // e.getMessage() contains help text + nested cause after the newline\n  logger.warn(\"Bad duration '{}': {}\", raw, e.getMessage());\n  ms = defaultMillis;\n}","preventionTips":["Sanitize all duration config strings once at startup, not at each use site.","Remember this message wraps all timeStringAs failures — read the nested line for the real cause.","Document the accepted format wherever users can edit your config files."],"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"}