MyCATApache/Mycat-Server · error · IllegalArgumentException
Interval year-month string was null
Error message
Interval year-month string was null
What it means
CalendarInterval.fromYearMonthString(s) converts a 'y-m' string into a CalendarInterval. It first rejects a null input with IllegalArgumentException 'Interval year-month string was null'. After trimming, a non-matching string fails with the year-month format error (handled under a separate index).
Solutions
- Check for null before calling and substitute a default interval or skip the record
- Coalesce with a default string: s == null ? "0-0" : s, if a zero interval is acceptable
- At the data layer, filter out or backfill NULL interval values before parsing
Example fix
// before
CalendarInterval i = CalendarInterval.fromYearMonthString(row.getString("interval")); // null
// after
String s = row.getString("interval");
CalendarInterval i = (s != null) ? CalendarInterval.fromYearMonthString(s) : new CalendarInterval(0, 0); Defensive patterns
Strategy: type-guard
Validate before calling
String s = raw == null ? null : raw.trim(); if (s == null || s.isEmpty()) return new CalendarInterval(0, 0); CalendarInterval i = CalendarInterval.fromYearMonthString(s);
Type guard
boolean isNonNullString(Object o) { return o instanceof String && !((String) o).isEmpty(); } Try / catch
try { CalendarInterval i = CalendarInterval.fromYearMonthString(s); } catch (IllegalArgumentException e) { log.warn("null or invalid interval input"); return CalendarInterval.ZERO; } Prevention
- Coalesce NULL columns to defaults before parsing
- Default optional interval params explicitly
- Filter missing interval fields upstream in ETL
- Always trim and null-check strings from external sources
When it happens
Trigger: Passing null directly to fromYearMonthString, typically when the value comes from an unpopulated SQL column, an absent config field, or a Map.get that returned null.
Common situations: NULL interval columns in a table; optional parameters not defaulted before parsing; JSON/ETL records missing the interval field.
Related errors
- outside range [ , ]
- 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/7d60be93411bc913.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/io/mycat/memory/unsafe/types/CalendarInterval.java:111
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);
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;View on GitHub (pinned to 65f8d8beb7)