MyCATApache/Mycat-Server · error · IllegalArgumentException
outside range [ , ]
Error message
%s %d outside range [%d, %d]
What it means
CalendarInterval.toLongWithRange parses a numeric string for an interval field (years, months, days, hours, minutes, seconds) and enforces a field-specific range. If the parsed value falls outside [minValue, maxValue], it throws IllegalArgumentException formatted as '<field> <value> outside range [<min>, <max>]'. Long.parseLong inside also throws NumberFormatException for non-numeric input.
Solutions
- Normalize the interval string so each component fits its valid range (months 0-11 within a year-month pair, hours 0-23, etc.)
- Validate components before constructing the interval string
- Catch IllegalArgumentException and surface a user-friendly message about the offending field
Example fix
// before String s = "1-13"; // month 13 out of range CalendarInterval i = CalendarInterval.fromYearMonthString(s); // after int months = 13; String s = (months / 12) + "-" + (months % 12); // "1-1" CalendarInterval i = CalendarInterval.fromYearMonthString(s);
Defensive patterns
Strategy: validation
Validate before calling
long months = Long.parseLong(monthPart);
if (months < 0 || months > 11) throw new IllegalArgumentException("month " + months + " outside range [0, 11]");
CalendarInterval i = CalendarInterval.fromYearMonthString(year + "-" + month); Type guard
boolean inRange(long v, long min, long max) { return v >= min && v <= max; } Try / catch
try { CalendarInterval i = CalendarInterval.fromYearMonthString(s); } catch (IllegalArgumentException e) { log.warn("bad interval " + s + ": " + e.getMessage()); } Prevention
- Normalize interval components (carry month 13 into years+1 month 1)
- Validate each field against its range before string construction
- Regexp the 'y-m' shape before parsing
- Catch IllegalArgumentException at the user-input boundary
When it happens
Trigger: Calling fromYearMonthString/fromDayTimeString or any of the interval field accessors with a component string whose numeric value exceeds the allowed range for that field, e.g. month 13, hours 25, or minutes 60 where the caller's range forbids it.
Common situations: Hand-built interval strings like '1-13' or '25:00:00' produced by user input or another system with different interval semantics; migrating data with unnormalized interval components.
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
- Interval year-month string was null
- Interval string does not match year-month format of 'y-m':
- Error parsing interval year-month string:
- Interval string does not match day-time format of 'd…
- Error parsing interval day-time string:
AI-assisted analysis of MyCATApache/Mycat-Server@65f8d8beb7 (2026-09-11).
Data as JSON: /api/errors/e261cc1d9204e687.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/io/mycat/memory/unsafe/types/CalendarInterval.java:96
long months = toLong(m.group(1)) * 12 + toLong(m.group(2));
long microseconds = toLong(m.group(3)) * MICROS_PER_WEEK;
microseconds += toLong(m.group(4)) * MICROS_PER_DAY;
microseconds += toLong(m.group(5)) * MICROS_PER_HOUR;
microseconds += toLong(m.group(6)) * MICROS_PER_MINUTE;
microseconds += toLong(m.group(7)) * MICROS_PER_SECOND;
microseconds += toLong(m.group(8)) * MICROS_PER_MILLI;
microseconds += toLong(m.group(9));
return new CalendarInterval((int) months, microseconds);
}
}
public static long toLongWithRange(String fieldName,
String s, long minValue, long maxValue) throws IllegalArgumentException {
long result = 0;
if (s != null) {
result = Long.parseLong(s);
if (result < minValue || result > maxValue) {
throw new IllegalArgumentException(String.format("%s %d outside range [%d, %d]",
fieldName, result, minValue, maxValue));
}
}
return result;
}
/**
* Parse YearMonth string in form: [-]YYYY-MM
*
* adapted from HiveIntervalYearMonth.valueOf
*/
public static CalendarInterval fromYearMonthString(String s) throws IllegalArgumentException {
CalendarInterval result = null;
if (s == null) {
throw new IllegalArgumentException("Interval year-month string was null");
}
s = s.trim();
Matcher m = yearMonthPattern.matcher(s);View on GitHub (pinned to 65f8d8beb7)