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

  1. Check for null before calling and substitute a default interval or skip the record
  2. Coalesce with a default string: s == null ? "0-0" : s, if a zero interval is acceptable
  3. 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

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


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)