{"record":{"id":"a98ec1401142eadb","repo":"MyCATApache/Mycat-Server","slug":"interval-string-does-not-match-year-month-format-o","errorCode":null,"errorMessage":"Interval string does not match year-month format of 'y-m': ","messagePattern":"Interval string does not match year-month format of 'y-m': ","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/memory/unsafe/types/CalendarInterval.java","lineNumber":116,"sourceCode":"      }\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;\n  }\n\n  /**\n   * Parse dayTime string in form: [-]d HH:mm:ss.nnnnnnnnn\n   *","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/memory/unsafe/types/CalendarInterval.java#L98-L134","documentation":"fromYearMonthString parses a '[-]y-m' interval literal such as '3-6'. This IllegalArgumentException is thrown when the input string does not match the year-month regex (yearMonthPattern), e.g. missing the dash, non-numeric parts, or extra text.","triggerScenarios":"Calling CalendarInterval.fromYearMonthString with a string that fails yearMonthPattern.matcher(s).matches(), e.g. fromYearMonthString(\"3 years 2 months\"), fromYearMonthString(\"3:6\"), fromYearMonthString(\"3-\").","commonSituations":"SQL interval literals typed in the wrong format in a Mycat SQL query, config values copied from another database dialect, user-supplied input passed straight to the parser.","solutions":["Fix the input string to the strict '[-]y-m' format, e.g. '3-6' or '-1-2'","Trim surrounding whitespace and remove quotes before parsing","Validate the string against the format with a regex before calling the API"],"exampleFix":"// before\nCalendarInterval iv = CalendarInterval.fromYearMonthString(\"3 years 6 months\");\n// after\nCalendarInterval iv = CalendarInterval.fromYearMonthString(\"3-6\");","handlingStrategy":"validation","validationCode":"private static final Pattern Y_M = Pattern.compile(\"^-?\\\\d+-\\\\d{1,2}$\");\nstatic void requireYearMonth(String s) {\n  if (s == null || !Y_M.matcher(s.trim()).matches())\n    throw new IllegalArgumentException(\"expected 'y-m', got: \" + s);\n}","typeGuard":"static boolean isYearMonthString(String s) {\n  return s != null && s.trim().matches(\"-?\\\\d+-\\\\d{1,2}\");\n}","tryCatchPattern":"try {\n  iv = CalendarInterval.fromYearMonthString(s);\n} catch (IllegalArgumentException e) {\n  log.error(\"Bad year-month interval '{}': {}\", s, e.getMessage());\n  iv = CalendarInterval.ZERO;\n}","preventionTips":["Always match the literal against ^-?\\d+-\\d{1,2}$ before parsing","Trim and dequote user input first","Never concatenate unit words like 'years' into the literal"],"tags":["java","parsing","interval","illegal-argument"],"backgroundTag":"invalid-argument-format","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"}