MyCATApache/Mycat-Server · error · IllegalArgumentException

Error parsing interval string:

Error message

Error parsing interval string: 

What it means

fromSingleUnitString throws this IllegalArgumentException when the numeric value parses but fails toLongWithRange checks or Long.parseLong (e.g. for 'microsecond'). The original exception is attached as cause.

Solutions

  1. Reduce the value or express it in a larger unit so it fits the allowed range
  2. Keep year values within +/- Integer.MAX_VALUE/12
  3. Catch the exception and read getCause().getMessage() for the failing field

Example fix

// before
CalendarInterval iv = CalendarInterval.fromSingleUnitString("year", "999999999999");
// after
CalendarInterval iv = CalendarInterval.fromSingleUnitString("year", "178956970"); // Integer.MAX_VALUE/12
Defensive patterns

Strategy: validation

Validate before calling

static void requireInRange(String unit, String s) {
  long v = Long.parseLong(s.trim());
  if (unit.equals("year") && Math.abs(v) > Integer.MAX_VALUE / 12L)
    throw new IllegalArgumentException("year value too large: " + v);
}

Try / catch

try {
  iv = CalendarInterval.fromSingleUnitString(unit, s);
} catch (IllegalArgumentException e) {
  throw new IllegalArgumentException("Interval value " + s + " out of range for " + unit, e.getCause());
}

Prevention

When it happens

Trigger: Value out of the allowed range for the unit, e.g. fromSingleUnitString("year", "999999999999") (year limited to Integer.MAX_VALUE/12), or a huge microsecond value overflowing long parse/conversion.

Common situations: Very large interval literals in SQL, values generated without range clamping, copy-pasted durations from other systems.

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/d64a50e5594a5993. Report an issue: GitHub.

Appendix: source

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

          long minute = toLongWithRange("minute", m.group(1),
            Long.MIN_VALUE / MICROS_PER_MINUTE, Long.MAX_VALUE / MICROS_PER_MINUTE);
          result = new CalendarInterval(0, minute * MICROS_PER_MINUTE);

        } else if (unit.equals("second")) {
          long micros = parseSecondNano(m.group(1));
          result = new CalendarInterval(0, micros);

        } else if (unit.equals("millisecond")) {
          long millisecond = toLongWithRange("millisecond", m.group(1),
                  Long.MIN_VALUE / MICROS_PER_MILLI, Long.MAX_VALUE / MICROS_PER_MILLI);
          result = new CalendarInterval(0, millisecond * MICROS_PER_MILLI);

        } else if (unit.equals("microsecond")) {
          long micros = Long.parseLong(m.group(1));
          result = new CalendarInterval(0, micros);
        }
      } catch (Exception e) {
        throw new IllegalArgumentException("Error parsing interval string: " + e.getMessage(), e);
      }
    }
    return result;
  }

  /**
   * Parse second_nano string in ss.nnnnnnnnn format to microseconds
   */
  public static long parseSecondNano(String secondNano) throws IllegalArgumentException {
    String[] parts = secondNano.split("\\.");
    if (parts.length == 1) {
      return toLongWithRange("second", parts[0], Long.MIN_VALUE / MICROS_PER_SECOND,
        Long.MAX_VALUE / MICROS_PER_SECOND) * MICROS_PER_SECOND;

    } else if (parts.length == 2) {
      long seconds = parts[0].equals("") ? 0L : toLongWithRange("second", parts[0],
        Long.MIN_VALUE / MICROS_PER_SECOND, Long.MAX_VALUE / MICROS_PER_SECOND);
      long nanos = toLongWithRange("nanosecond", parts[1], 0L, 999999999L);

View on GitHub (pinned to 65f8d8beb7)