quarkusio/quarkus · error · IllegalArgumentException

Cannot use `MAXLEN` and `MINID` together

Error message

Cannot use `MAXLEN` and `MINID` together

What it means

XTRIM supports two mutually exclusive trimming strategies: MAXLEN (trim by entry count) and MINID (trim by entry ID threshold). The Redis protocol does not allow both in one command, so XTrimArgs.toArgs() throws this IllegalArgumentException when both maxlen(long) and minid(String) have been set on the same args object.

Source

Thrown at extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/stream/XTrimArgs.java:71

    /**
     * Sets the maximum entries that can get evicted.
     *
     * @param limit the limit, must be positive
     * @return the current {@code XAddArgs}
     */
    public XTrimArgs limit(long limit) {
        this.limit = limit;
        return this;
    }

    @Override
    public List<Object> toArgs() {
        List<Object> args = new ArrayList<>();

        if (maxlen >= 0) {
            if (minid != null) {
                throw new IllegalArgumentException("Cannot use `MAXLEN` and `MINID` together");
            }

            args.add("MAXLEN");
            if (approximateTrimming) {
                args.add("~");
            } else {
                args.add("=");
            }
            args.add(Long.toString(maxlen));
        }

        if (minid != null) {
            args.add("MINID");
            if (approximateTrimming) {
                args.add("~");
            } else {
                args.add("=");
            }

View on GitHub (pinned to e1c734241f)

Solutions

  1. Remove either the maxlen(...) or the minid(...) call so only one trimming strategy is set
  2. If both policies come from config, enforce a single strategy choice before constructing XTrimArgs
  3. Pick the strategy matching your semantics: maxlen for entry-count caps, minid for time/ID-based eviction

Example fix

// before
XTrimArgs args = new XTrimArgs().maxlen(1000).minid("1526505285000-0");
// after
XTrimArgs args = new XTrimArgs().minid("1526505285000-0");
Defensive patterns

Strategy: validation

Validate before calling

if (args.maxlen >= 0 && args.minid != null) {
    throw new IllegalArgumentException("Configure either maxlen or minid for XTRIM, not both");
}

Type guard

boolean isValidTrimArgs(XTrimArgs a) {
    return a != null;
}

Try / catch

try {
    streamCommands.xtrim(key, args);
} catch (IllegalArgumentException e) {
    log.error("Invalid XTRIM args: " + e.getMessage());
}

Prevention

When it happens

Trigger: Calling XTrimArgs.builder-style chaining that sets both, e.g. new XTrimArgs().maxlen(1000).minid("1234-0"), then passing it to streamCommands.xtrim(key, args) — the error surfaces at toArgs() time when the command arguments are built.

Common situations: Building args from configuration where both a max-length and a min-ID policy are configured (e.g. both properties set in application config), or refactoring from a MAXLEN policy to MINID without removing the maxlen(...) call.

Related errors


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