MyCATApache/Mycat-Server · error · IllegalArgumentException
Error parsing interval year-month string:
Error message
Error parsing interval year-month string:
What it means
After the regex matches, fromYearMonthString converts the year and month groups with toLongWithRange, which enforces ranges (year: 0..Integer.MAX_VALUE, month: 0..11). Any exception there (number too large or month > 11) is rethrown as this IllegalArgumentException with the cause attached.
Solutions
- Normalize the literal so months are 0-11 and years fit in an int (e.g. use '4-0' instead of '3-12')
- Keep years within 0..Integer.MAX_VALUE
- Catch IllegalArgumentException and inspect getCause() for the exact range violation
Example fix
// before
CalendarInterval iv = CalendarInterval.fromYearMonthString("3-12");
// after
CalendarInterval iv = CalendarInterval.fromYearMonthString("4-0"); Defensive patterns
Strategy: validation
Validate before calling
static void requireValidYearMonth(String s) {
Matcher m = Pattern.compile("^(-)?(\\d+)-(\\d+)$").matcher(s.trim());
if (!m.matches()) return;
long years = Long.parseLong(m.group(2)), months = Long.parseLong(m.group(3));
if (years > Integer.MAX_VALUE) throw new IllegalArgumentException("year out of range");
if (months > 11) throw new IllegalArgumentException("month must be 0-11");
} Try / catch
try {
iv = CalendarInterval.fromYearMonthString(s);
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Invalid interval " + s, e.getCause());
} Prevention
- Normalize months to 0-11 before parsing
- Keep year components within int range
- Log e.getCause() to identify which field was out of range
When it happens
Trigger: Calling fromYearMonthString with a format-matching string whose parts are out of range, e.g. "2147483648-0" (year overflow) or "3-12" (month > 11).
Common situations: Hand-written interval literals with month components of 12 or more, auto-generated intervals from another system with different range semantics, extreme values that overflow Integer.MAX_VALUE years.
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
- Error parsing interval day-time string:
- Error parsing interval string:
- outside range [ , ]
- Interval year-month string was null
- Interval string does not match year-month format of 'y-m':
AI-assisted analysis of MyCATApache/Mycat-Server@65f8d8beb7 (2026-09-11).
Data as JSON: /api/errors/2aeed1c3be34aa48.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/io/mycat/memory/unsafe/types/CalendarInterval.java:125
*/
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);
if (!m.matches()) {
throw new IllegalArgumentException(
"Interval string does not match year-month format of 'y-m': " + s);
} else {
try {
int sign = m.group(1) != null && m.group(1).equals("-") ? -1 : 1;
int years = (int) toLongWithRange("year", m.group(2), 0, Integer.MAX_VALUE);
int months = (int) toLongWithRange("month", m.group(3), 0, 11);
result = new CalendarInterval(sign * (years * 12 + months), 0);
} catch (Exception e) {
throw new IllegalArgumentException(
"Error parsing interval year-month string: " + e.getMessage(), e);
}
}
return result;
}
/**
* Parse dayTime string in form: [-]d HH:mm:ss.nnnnnnnnn
*
* adapted from HiveIntervalDayTime.valueOf
*/
public static CalendarInterval fromDayTimeString(String s) throws IllegalArgumentException {
CalendarInterval result = null;
if (s == null) {
throw new IllegalArgumentException("Interval day-time string was null");
}
s = s.trim();
Matcher m = dayTimePattern.matcher(s);View on GitHub (pinned to 65f8d8beb7)