{"record":{"id":"2aeed1c3be34aa48","repo":"MyCATApache/Mycat-Server","slug":"error-parsing-interval-year-month-string","errorCode":null,"errorMessage":"Error parsing interval year-month string: ","messagePattern":"Error parsing interval year-month string: ","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/memory/unsafe/types/CalendarInterval.java","lineNumber":125,"sourceCode":"   */\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;\n  }\n\n  /**\n   * Parse dayTime string in form: [-]d HH:mm:ss.nnnnnnnnn\n   *\n   * adapted from HiveIntervalDayTime.valueOf\n   */\n  public static CalendarInterval fromDayTimeString(String s) throws IllegalArgumentException {\n    CalendarInterval result = null;\n    if (s == null) {\n      throw new IllegalArgumentException(\"Interval day-time string was null\");\n    }\n    s = s.trim();\n    Matcher m = dayTimePattern.matcher(s);","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/memory/unsafe/types/CalendarInterval.java#L107-L143","documentation":"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.","triggerScenarios":"Calling fromYearMonthString with a format-matching string whose parts are out of range, e.g. \"2147483648-0\" (year overflow) or \"3-12\" (month > 11).","commonSituations":"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.","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"],"exampleFix":"// before\nCalendarInterval iv = CalendarInterval.fromYearMonthString(\"3-12\");\n// after\nCalendarInterval iv = CalendarInterval.fromYearMonthString(\"4-0\");","handlingStrategy":"validation","validationCode":"static void requireValidYearMonth(String s) {\n  Matcher m = Pattern.compile(\"^(-)?(\\\\d+)-(\\\\d+)$\").matcher(s.trim());\n  if (!m.matches()) return;\n  long years = Long.parseLong(m.group(2)), months = Long.parseLong(m.group(3));\n  if (years > Integer.MAX_VALUE) throw new IllegalArgumentException(\"year out of range\");\n  if (months > 11) throw new IllegalArgumentException(\"month must be 0-11\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  iv = CalendarInterval.fromYearMonthString(s);\n} catch (IllegalArgumentException e) {\n  throw new IllegalArgumentException(\"Invalid interval \" + s, e.getCause());\n}","preventionTips":["Normalize months to 0-11 before parsing","Keep year components within int range","Log e.getCause() to identify which field was out of range"],"tags":["java","parsing","interval","range"],"backgroundTag":"value-out-of-range","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"}