{"record":{"id":"1add1455b8528e29","repo":"MyCATApache/Mycat-Server","slug":"failed-to-parse-byte-string-str","errorCode":null,"errorMessage":"Failed to parse byte string: ${str}","messagePattern":"Failed to parse byte string: (.+?)","errorType":"validation","errorClass":"NumberFormatException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/memory/unsafe/utils/JavaUtils.java","lineNumber":215,"sourceCode":"      Matcher m = Pattern.compile(\"([0-9]+)([a-z]+)?\").matcher(lower);\n      Matcher fractionMatcher = Pattern.compile(\"([0-9]+\\\\.[0-9]+)([a-z]+)?\").matcher(lower);\n\n      if (m.matches()) {\n        long val = Long.parseLong(m.group(1));\n        String suffix = m.group(2);\n\n        // Check for invalid suffixes\n        if (suffix != null && !byteSuffixes.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.convertFrom(val, suffix != null ? byteSuffixes.get(suffix) : unit);\n      } else if (fractionMatcher.matches()) {\n        throw new NumberFormatException(\"Fractional values are not supported. Input was: \"\n          + fractionMatcher.group(1));\n      } else {\n        throw new NumberFormatException(\"Failed to parse byte string: \" + str);\n      }\n\n    } catch (NumberFormatException e) {\n      String byteError = \"Size must be specified as bytes (b), \" +\n        \"kibibytes (k), mebibytes (m), gibibytes (g), tebibytes (t), or pebibytes(p). \" +\n        \"E.g. 50b, 100k, or 250m.\";\n\n      throw new NumberFormatException(byteError + \"\\n\" + e.getMessage());\n    }\n  }\n\n  /**\n   * Convert a passed byte string (e.g. 50b, 100k, or 250m) to bytes for\n   * internal use.\n   *\n   * If no suffix is provided, the passed number is assumed to be in bytes.\n   */\n  public static long byteStringAsBytes(String str) {","sourceCodeStart":197,"sourceCodeEnd":233,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/memory/unsafe/utils/JavaUtils.java#L197-L233","documentation":"byteStringAs throws this NumberFormatException when the input matches neither the integer-byte pattern nor the fraction pattern — i.e. the string is not a recognizable byte size at all. Like the time parser, the wrapping catch (byteError) appends the accepted units help text.","triggerScenarios":"Passing empty strings, pure unit-less text (\"abc\"), values with internal spaces (\"100 m\"), negative fractional forms outside both patterns, or unresolved placeholders like \"${memory}\" to byteStringAsBytes/Kb/Mb/Gb.","commonSituations":"Missing or empty properties entries; placeholders not substituted by the config system; values like \"100 MB\" with spaces copied from documentation.","solutions":["Fix the value to the format: signed integer plus optional b/k/m/g/t/p suffix (e.g. 50b, 100k, 250m), no spaces.","Substitute/remove unresolved ${...} placeholders before parsing.","Guard with a default for missing/empty config values."],"exampleFix":"// before\nlong bytes = JavaUtils.byteStringAsBytes(props.getProperty(\"mem\")); // \"\"\n// after\nString raw = props.getProperty(\"mem\", \"512m\").trim().replace(\" \", \"\");\nlong bytes = JavaUtils.byteStringAsBytes(raw);","handlingStrategy":"validation","validationCode":"if (raw == null || !raw.trim().replace(\" \", \"\").toLowerCase().matches(\"-?[0-9]+([a-z]+)?\")) {\n  raw = \"512m\"; // safe default\n}","typeGuard":null,"tryCatchPattern":"long bytes;\ntry {\n  bytes = JavaUtils.byteStringAsBytes(raw);\n} catch (NumberFormatException e) {\n  logger.warn(\"Bad byte size '{}': {}\", raw, e.getMessage());\n  bytes = defaultBytes;\n}","preventionTips":["Ensure config placeholders like ${memory} are actually substituted before parsing.","Strip spaces and trim values copied from docs or environment variables.","Use a shared sanitize step for all size strings at config-load time."],"tags":["java","parsing","configuration","memory"],"backgroundTag":"invalid-config-value","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"}