quarkusio/quarkus · error · IllegalArgumentException

Invalid duration: ${value}

Error message

Invalid duration: ${value}

What it means

DurationConverter.parseDuration() converts config strings to java.time.Duration, supporting plain numbers, '1h30m' style compound values, and standard ISO-8601. Any parse failure is wrapped in IllegalArgumentException("Invalid duration: <value>").

Source

Thrown at core/runtime/src/main/java/io/quarkus/runtime/configuration/DurationConverter.java:79

                return Duration.ofMillis(Long.parseLong(num));
        }

        // cases handled by Duration.parse(), we add the P/PT prefix if needed
        try {
            if (isDecimal(numericPart)) {
                if (lastLower == 'h' || lastLower == 'm' || lastLower == 's') {
                    return Duration.parse(PERIOD_OF_TIME + value);
                } else if (lastLower == 'd') {
                    return Duration.parse(PERIOD + value);
                }
            }
            // Handle "1h30m" style (DIGITS_AND_UNIT)
            if (startsLikeDigits(value)) {
                return Duration.parse(PERIOD_OF_TIME + value);
            }
            return Duration.parse(value);
        } catch (Exception e) {
            throw new IllegalArgumentException("Invalid duration: " + value, e);
        }
    }

    private static boolean isNumeric(String s) {
        int len = s.length();
        if (len == 0) {
            return false;
        }
        int i = (s.charAt(0) == '-' || s.charAt(0) == '+') ? 1 : 0;
        if (i == len) {
            return false;
        }
        for (; i < len; i++) {
            char c = s.charAt(i);
            if (c < '0' || c > '9') {
                return false;
            }
        }

View on GitHub (pinned to e1c734241f)

Solutions

  1. Use accepted forms: '5S'/'5s', ISO-8601 'PT30S', 'PT1H30M', or compound '1h30m' without spaces.
  2. Remove stray whitespace/quotes from the value (env vars especially).
  3. Verify unit letters: s, m, h, d (and ms-style handling per converter docs).
  4. Test the literal with Duration.parse('PT'+value) locally to see the underlying error.

Example fix

# before
quarkus.http.read-timeout=30 seconds
# after
quarkus.http.read-timeout=30s
Defensive patterns

Strategy: validation

Validate before calling

boolean isValidDuration(String s) {
    if (s == null || s.isBlank()) return false;
    String v = s.trim();
    try {
        if (v.chars().allMatch(Character::isDigit)) return true; // seconds
        java.time.Duration.parse(v.startsWith("P") ? v : "PT" + v);
        return true;
    } catch (Exception e) { return false; }
}

Type guard

java.time.Duration tryParseDuration(String s) {
    try { return (s == null || s.isBlank()) ? null : java.time.Duration.parse(s.matches("\\d+") ? "PT" + s.trim() + "S" : s.trim()); }
    catch (Exception e) { return null; }
}

Try / catch

try {
    // use converted Duration
} catch (IllegalArgumentException e) {
    if (e.getMessage().startsWith("Invalid duration:")) {
        log.errorf("Fix duration format (e.g. 30s, PT30S, 1h30m): %s", e.getMessage());
    } else { throw e; }
}

Prevention

When it happens

Trigger: Setting a duration-typed property (timeouts, intervals, TTLs) with an unparseable value: misspelled units ('30sec' instead of '30s'), stray whitespace inside, negative in the wrong format, or a non-ISO string like '5 minutes'.

Common situations: Typos like '30ms s', 'PT' missing for ISO style, using '1h 30m' with a space, env-var values with trailing spaces or quotes, upgrading Quarkus and the converter is stricter than the old parser.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/94744dab02522625. Report an issue: GitHub.