{"record":{"id":"7d60be93411bc913","repo":"MyCATApache/Mycat-Server","slug":"interval-year-month-string-was-null","errorCode":null,"errorMessage":"Interval year-month string was null","messagePattern":"Interval year-month string was null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/memory/unsafe/types/CalendarInterval.java","lineNumber":111,"sourceCode":"    if (s != null) {\n      result = Long.parseLong(s);\n      if (result < minValue || result > maxValue) {\n        throw new IllegalArgumentException(String.format(\"%s %d outside range [%d, %d]\",\n          fieldName, result, minValue, maxValue));\n      }\n    }\n    return result;\n  }\n\n  /**\n   * Parse YearMonth string in form: [-]YYYY-MM\n   *\n   * adapted from HiveIntervalYearMonth.valueOf\n   */\n  public static CalendarInterval fromYearMonthString(String s) throws IllegalArgumentException {\n    CalendarInterval result = null;\n    if (s == null) {\n      throw new IllegalArgumentException(\"Interval year-month string was null\");\n    }\n    s = s.trim();\n    Matcher m = yearMonthPattern.matcher(s);\n    if (!m.matches()) {\n      throw new IllegalArgumentException(\n        \"Interval string does not match year-month format of 'y-m': \" + s);\n    } else {\n      try {\n        int sign = m.group(1) != null && m.group(1).equals(\"-\") ? -1 : 1;\n        int years = (int) toLongWithRange(\"year\", m.group(2), 0, Integer.MAX_VALUE);\n        int months = (int) toLongWithRange(\"month\", m.group(3), 0, 11);\n        result = new CalendarInterval(sign * (years * 12 + months), 0);\n      } catch (Exception e) {\n        throw new IllegalArgumentException(\n          \"Error parsing interval year-month string: \" + e.getMessage(), e);\n      }\n    }\n    return result;","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/memory/unsafe/types/CalendarInterval.java#L93-L129","documentation":"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).","triggerScenarios":"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.","commonSituations":"NULL interval columns in a table; optional parameters not defaulted before parsing; JSON/ETL records missing the interval field.","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"],"exampleFix":"// before\nCalendarInterval i = CalendarInterval.fromYearMonthString(row.getString(\"interval\")); // null\n// after\nString s = row.getString(\"interval\");\nCalendarInterval i = (s != null) ? CalendarInterval.fromYearMonthString(s) : new CalendarInterval(0, 0);","handlingStrategy":"type-guard","validationCode":"String s = raw == null ? null : raw.trim();\nif (s == null || s.isEmpty()) return new CalendarInterval(0, 0);\nCalendarInterval i = CalendarInterval.fromYearMonthString(s);","typeGuard":"boolean isNonNullString(Object o) { return o instanceof String && !((String) o).isEmpty(); }","tryCatchPattern":"try { CalendarInterval i = CalendarInterval.fromYearMonthString(s); } catch (IllegalArgumentException e) { log.warn(\"null or invalid interval input\"); return CalendarInterval.ZERO; }","preventionTips":["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"],"tags":["java","interval","null-argument","parsing"],"backgroundTag":"null-argument","analyzedSha":"65f8d8beb752f935752f2a0eec0ab017facab9ef","analyzedAt":"2026-09-11T00:12:21.696Z","contentChangedAt":"2026-09-11T00:12:21.696Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}