MyCATApache/Mycat-Server · error · IllegalArgumentException

Error parsing interval day-time string:

Error message

Error parsing interval day-time string: 

What it means

After regex matching, fromDayTimeString converts day/hour/minute/second/nanosecond groups with toLongWithRange (hours 0-23, minutes 0-59, seconds 0-59, nanos 0-999999999) and checks overflow of the microsecond total. Any exception is rethrown as this IllegalArgumentException with the original cause.

Solutions

  1. Normalize each field into range (hours 0-23, minutes 0-59, seconds 0-59)
  2. Carry excess units into days (e.g. '1 25:00:00.0' -> '2 01:00:00.0')
  3. Limit fractional seconds to 9 digits

Example fix

// before
CalendarInterval iv = CalendarInterval.fromDayTimeString("1 25:30:00.0");
// after
CalendarInterval iv = CalendarInterval.fromDayTimeString("2 01:30:00.0");
Defensive patterns

Strategy: validation

Validate before calling

static void requireDayTimeRanges(String s) {
  String[] p = s.trim().replaceFirst("^-", "").split("[ :.]");
  if (Long.parseLong(p[1]) > 23 || Long.parseLong(p[2]) > 59 || Long.parseLong(p[3]) > 59)
    throw new IllegalArgumentException("hour/min/sec out of range");
  if (p.length > 4 && p[4].length() > 9)
    throw new IllegalArgumentException("nanoseconds exceed 9 digits");
}

Try / catch

try {
  iv = CalendarInterval.fromDayTimeString(s);
} catch (IllegalArgumentException e) {
  throw new IllegalArgumentException("Invalid day-time interval " + s, e.getCause());
}

Prevention

When it happens

Trigger: Calling fromDayTimeString with a format-matching string containing out-of-range parts, e.g. "1 25:00:00.0" (hour 25), "1 12:75:00.0" (minute 75), or "1 12:00:00.1234567890" (nano overflow).

Common situations: Durations computed by external tools that do not normalize time units, hand-edited literals with hour values >= 24, more than 9 digits of fractional seconds.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of MyCATApache/Mycat-Server@65f8d8beb7 (2026-09-11). Data as JSON: /api/errors/af5a959b1a03d730. Report an issue: GitHub.

Appendix: source

Thrown at src/main/java/io/mycat/memory/unsafe/types/CalendarInterval.java:160

    s = s.trim();
    Matcher m = dayTimePattern.matcher(s);
    if (!m.matches()) {
      throw new IllegalArgumentException(
        "Interval string does not match day-time format of 'd h:m:s.n': " + s);
    } else {
      try {
        int sign = m.group(1) != null && m.group(1).equals("-") ? -1 : 1;
        long days = toLongWithRange("day", m.group(2), 0, Integer.MAX_VALUE);
        long hours = toLongWithRange("hour", m.group(3), 0, 23);
        long minutes = toLongWithRange("minute", m.group(4), 0, 59);
        long seconds = toLongWithRange("second", m.group(5), 0, 59);
        // Hive allow nanosecond precision interval
        long nanos = toLongWithRange("nanosecond", m.group(7), 0L, 999999999L);
        result = new CalendarInterval(0, sign * (
          days * MICROS_PER_DAY + hours * MICROS_PER_HOUR + minutes * MICROS_PER_MINUTE +
          seconds * MICROS_PER_SECOND + nanos / 1000L));
      } catch (Exception e) {
        throw new IllegalArgumentException(
          "Error parsing interval day-time string: " + e.getMessage(), e);
      }
    }
    return result;
  }

  public static CalendarInterval fromSingleUnitString(String unit, String s)
      throws IllegalArgumentException {

    CalendarInterval result = null;
    if (s == null) {
      throw new IllegalArgumentException(String.format("Interval %s string was null", unit));
    }
    s = s.trim();
    Matcher m = quoteTrimPattern.matcher(s);
    if (!m.matches()) {
      throw new IllegalArgumentException(
        "Interval string does not match day-time format of 'd h:m:s.n': " + s);

View on GitHub (pinned to 65f8d8beb7)