apache/incubator-seata · error · IllegalArgumentException

endTime must not be earlier than startTime

Error message

endTime must not be earlier than startTime

What it means

DateUtils.judgeExceedTimeDuration throws IllegalArgumentException when endTime < startTime, before even evaluating whether the range exceeds maxDuration. Console MCP query tools use it to bound time-range queries, so an inverted range is rejected immediately rather than producing a negative duration.

Source

Thrown at console/src/main/java/org/apache/seata/mcp/core/utils/DateUtils.java:73

            throw new DateTimeException("The time format does not match yyyy-MM-dd HH:mm:ss", e);
        }
    }

    public static String convertToDateTimeFromTimestamp(Long timestamp) {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime dateTime;
        try {
            dateTime = Instant.ofEpochMilli(timestamp)
                    .atZone(ZoneId.systemDefault())
                    .toLocalDateTime();
        } catch (DateTimeException | ArithmeticException e) {
            return "Parse Failed, please check that the timestamp is correct";
        }
        return dateTime.format(formatter);
    }

    public static boolean judgeExceedTimeDuration(Long startTime, Long endTime, Long maxDuration) {
        if (endTime < startTime) throw new IllegalArgumentException("endTime must not be earlier than startTime");
        return endTime - startTime > maxDuration;
    }

    public static Long convertToHourFromTimeStamp(Long timestamp) {
        return timestamp / (60 * 60 * 1000);
    }
}

View on GitHub (pinned to e01f97c6db)

Solutions

  1. Swap the arguments so startTime <= endTime
  2. Verify both timestamps were converted with the same timezone/zone rule before comparison
  3. Add a client-side guard: if (end < start) throw early with a clear message before calling the tool
  4. For date-string inputs, compare them lexicographically first — 'yyyy-MM-dd' strings sort chronologically

Example fix

// before
boolean exceeded = DateUtils.judgeExceedTimeDuration(endTs, startTs, MAX); // inverted -> throws

// after
boolean exceeded = DateUtils.judgeExceedTimeDuration(startTs, endTs, MAX);
Defensive patterns

Strategy: validation

Validate before calling

if (endTime == null || startTime == null || endTime < startTime) throw new IllegalArgumentException("startTime must be <= endTime");

Type guard

boolean isValidRange(long start, long end) { return end >= start; }

Try / catch

try { DateUtils.judgeExceedTimeDuration(start, end, max); } catch (IllegalArgumentException e) { return toolError("endTime precedes startTime"); }

Prevention

When it happens

Trigger: MCP tool invocations for history/metrics where the endTime parameter is chronologically before startTime — e.g. passing startTime=2026-08-14 and endTime=2026-08-01, or mixing up the two converted timestamps.

Common situations: Swapping start/end arguments in tool calls, client-side sorting bugs, or timezone conversion of the two endpoints by different rules so the computed end millisecond value lands before the start.

Related errors


AI-assisted analysis of apache/incubator-seata@e01f97c6db (2026-08-14). Data as JSON: /api/errors/1bc52765c68c5346. Report an issue: GitHub.