apache/incubator-seata · error · UnsupportedOperationException
"\"" + str + "\" can't parse to Duration"
Error message
"\"" + str + "\" can't parse to Duration"
What it means
DurationUtil.parse accepts a simple format <number><unit> where unit is ms, d, h, m, or s, an ISO-8601 duration (P...), or a bare integer interpreted as milliseconds. This branch fires when the SIMPLE regex matched (digits plus 1-2 letters) but the unit letter is none of the supported ones — note the bug-prone ordering: 'm' alone is ambiguous with 'ms', and units like 'w' or 'y' are unsupported.
Source
Thrown at common/src/main/java/org/apache/seata/common/util/DurationUtil.java:58
if (SIMPLE.matcher(str).matches()) {
if (str.contains(MILLIS_SECOND_UNIT)) {
long value = doParse(MILLIS_SECOND_UNIT, str);
return Duration.ofMillis(value);
} else if (str.contains(DAY_UNIT)) {
long value = doParse(DAY_UNIT, str);
return Duration.ofDays(value);
} else if (str.contains(HOUR_UNIT)) {
long value = doParse(HOUR_UNIT, str);
return Duration.ofHours(value);
} else if (str.contains(MINUTE_UNIT)) {
long value = doParse(MINUTE_UNIT, str);
return Duration.ofMinutes(value);
} else if (str.contains(SECOND_UNIT)) {
long value = doParse(SECOND_UNIT, str);
return Duration.ofSeconds(value);
} else {
throw new UnsupportedOperationException("\"" + str + "\" can't parse to Duration");
}
}
try {
if (ISO8601.matcher(str).matches()) {
return Duration.parse(str);
}
} catch (DateTimeParseException e) {
throw new UnsupportedOperationException("\"" + str + "\" can't parse to Duration", e);
}
try {
int millis = Integer.parseInt(str);
return Duration.ofMillis(millis);
} catch (Exception e) {
throw new UnsupportedOperationException("\"" + str + "\" can't parse to Duration", e);
}
}View on GitHub (pinned to e01f97c6db)
Solutions
- Convert the value to a supported unit: ms, s, m, h, or d (e.g. 10w -> 70d).
- Use exact ISO-8601 (PT168H) for unusual durations.
- Bare numbers are milliseconds — make sure you did not intend seconds when writing '30' (write '30s' instead).
Example fix
# before seata.tm.degrade-check.period=10w # after seata.tm.degrade-check.period=70d
Defensive patterns
Strategy: validation
Validate before calling
// Accept only the documented simple units before parsing
private static final Pattern DURATION_OK = Pattern.compile("^[+-]?\\d+(ms|s|m|h|d)?$");
if (value != null && !value.isBlank() && !DURATION_OK.matcher(value).matches()
&& !value.matches("^[+-]?P.*$")) {
throw new IllegalArgumentException("Unsupported duration value: " + value
+ " (use e.g. 30s, 5m, 2h, 7d, 2500ms, ISO-8601, or plain millis)");
}
Duration d = DurationUtil.parse(value); Type guard
boolean isSupportedSimpleUnit(String unit) {
return Set.of("ms", "s", "m", "h", "d").contains(unit.toLowerCase());
} Try / catch
try {
Duration d = DurationUtil.parse(str);
} catch (UnsupportedOperationException e) {
// message shows the exact string; map to a user-facing config error with valid examples
throw new IllegalArgumentException("Invalid duration '" + str + "'. Examples: 30s, 5m, 2h, 7d, 2500ms", e);
} Prevention
- Stick to ms/s/m/h/d units; there is no w or y.
- Units are matched case-sensitively in practice — write lowercase to be safe.
- A bare number means milliseconds; never assume seconds.
When it happens
Trigger: DurationUtil.parse("10w"), parse("5y"), parse("3sec"), or any value matching ^[+-]?\d+[a-zA-Z]{1,2}$ whose letters are not ms/d/h/m/s — e.g. when a timeout property such as seata client RM/TM timeout configs is given an unsupported unit.
Common situations: Configuring seata timeouts (e.g. tm.degrade-check period, client heartbeat intervals) with 'w'/'y'/'hr' units; using java.time-style units like '30S' (uppercase S fails the unit tests since matching is case-sensitive); trailing whitespace trimmed to letters.
Related errors
- not found service provider for : {}
- Invalid port number in: {}
- Invalid format for endpoint: {}
- unknown lock mode:{}
- unknown session mode:{}
AI-assisted analysis of apache/incubator-seata@e01f97c6db (2026-08-14).
Data as JSON: /api/errors/94199683ecca3e04.
Report an issue: GitHub.