apache/incubator-seata · error · IllegalArgumentException
could not convert '{size}' to byte length
Error message
could not convert '{size}' to byte length What it means
Thrown by SizeUtil.size2Long when the input size string is null or has length <= 1, so it cannot possibly contain a number plus a unit. The library requires at least two characters: a numeric part and one of the unit characters k/m/g/t.
Source
Thrown at common/src/main/java/org/apache/seata/common/util/SizeUtil.java:33
* limitations under the License.
*/
package org.apache.seata.common.util;
public class SizeUtil {
private static final long RADIX = 1024;
/**
* case size to byte length
* example:
* 2k => 2 * 1024
* 2m => 2 * 1024 * 1024
* 2g => 2 * 1024 * 1024 * 1024
* 2t => 2 * 1024 * 1024 * 1024 * 1024
* @param size the string size with unit
* @return the byte length
*/
public static long size2Long(String size) {
if (null == size || size.length() <= 1) {
throw new IllegalArgumentException("could not convert '" + size + "' to byte length");
}
String size2Lower = size.toLowerCase();
char unit = size2Lower.charAt(size.length() - 1);
long number;
try {
number = NumberUtils.toLong(size2Lower.substring(0, size.length() - 1));
} catch (NumberFormatException | NullPointerException ex) {
throw new IllegalArgumentException("could not convert '" + size + "' to byte length");
}
switch (unit) {
case 'k':
return number * RADIX;
case 'm':
return number * RADIX * RADIX;
case 'g':
return number * RADIX * RADIX * RADIX;View on GitHub (pinned to e01f97c6db)
Solutions
- Provide a value with both number and unit, e.g. '2k', '64m', '1g'.
- Check the corresponding config key is actually set and the placeholder resolved (not null/empty).
- Default the property in code when it may be absent instead of passing null through.
Example fix
// before
long max = SizeUtil.size2Long(null); // IllegalArgumentException
long max = SizeUtil.size2Long("8"); // no unit
// after
long max = SizeUtil.size2Long("8k"); Defensive patterns
Strategy: validation
Validate before calling
private static final Pattern SIZE = Pattern.compile("^\\d+[kKmMgGtT]$");
boolean valid(String size) {
return size != null && SIZE.matcher(size).matches();
}
long parse(String size) {
if (!valid(size)) throw new IllegalArgumentException("Bad size: " + size);
return SizeUtil.size2Long(size);
} Try / catch
try {
return SizeUtil.size2Long(size);
} catch (IllegalArgumentException e) {
LOGGER.warn("Invalid size '{}', falling back to default {}", size, defaultSize);
return defaultSize;
} Prevention
- Validate size config with a strict regex at startup, fail fast with the offending key name.
- Document supported format (integer + k/m/g/t) next to every size property.
- Never pass unresolved placeholders to size2Long — check for null first.
When it happens
Trigger: Calling SizeUtil.size2Long(size) with null, "", or a single character like "k" or "5" (no unit). The check is done before any parsing, purely on length.
Common situations: Configuration properties for max request/body sizes left empty or set to a bare number without a unit (e.g. maxCommitRetryTimeoutInSeconds-style size keys like 'maxMessageSize=8' instead of '8k'); property placeholder resolving to null at runtime; copy-paste truncation in config files.
Related errors
- {dataName} data is too large, size={length}
- Unknown BranchType[{name}]
- TCC bean name cannot be null or empty
- not support config type:
- the {%s} can't be empty
AI-assisted analysis of apache/incubator-seata@e01f97c6db (2026-08-14).
Data as JSON: /api/errors/1d5dc8d6f2f58452.
Report an issue: GitHub.