{"record":{"id":"e261cc1d9204e687","repo":"MyCATApache/Mycat-Server","slug":"s-d-outside-range-d-d","errorCode":null,"errorMessage":"%s %d outside range [%d, %d]","messagePattern":"(.+?) (.+?) outside range \\[(.+?), (.+?)\\]","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/memory/unsafe/types/CalendarInterval.java","lineNumber":96,"sourceCode":"      long months = toLong(m.group(1)) * 12 + toLong(m.group(2));\n      long microseconds = toLong(m.group(3)) * MICROS_PER_WEEK;\n      microseconds += toLong(m.group(4)) * MICROS_PER_DAY;\n      microseconds += toLong(m.group(5)) * MICROS_PER_HOUR;\n      microseconds += toLong(m.group(6)) * MICROS_PER_MINUTE;\n      microseconds += toLong(m.group(7)) * MICROS_PER_SECOND;\n      microseconds += toLong(m.group(8)) * MICROS_PER_MILLI;\n      microseconds += toLong(m.group(9));\n      return new CalendarInterval((int) months, microseconds);\n    }\n  }\n\n  public static long toLongWithRange(String fieldName,\n      String s, long minValue, long maxValue) throws IllegalArgumentException {\n    long result = 0;\n    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);","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/memory/unsafe/types/CalendarInterval.java#L78-L114","documentation":"CalendarInterval.toLongWithRange parses a numeric string for an interval field (years, months, days, hours, minutes, seconds) and enforces a field-specific range. If the parsed value falls outside [minValue, maxValue], it throws IllegalArgumentException formatted as '<field> <value> outside range [<min>, <max>]'. Long.parseLong inside also throws NumberFormatException for non-numeric input.","triggerScenarios":"Calling fromYearMonthString/fromDayTimeString or any of the interval field accessors with a component string whose numeric value exceeds the allowed range for that field, e.g. month 13, hours 25, or minutes 60 where the caller's range forbids it.","commonSituations":"Hand-built interval strings like '1-13' or '25:00:00' produced by user input or another system with different interval semantics; migrating data with unnormalized interval components.","solutions":["Normalize the interval string so each component fits its valid range (months 0-11 within a year-month pair, hours 0-23, etc.)","Validate components before constructing the interval string","Catch IllegalArgumentException and surface a user-friendly message about the offending field"],"exampleFix":"// before\nString s = \"1-13\"; // month 13 out of range\nCalendarInterval i = CalendarInterval.fromYearMonthString(s);\n// after\nint months = 13;\nString s = (months / 12) + \"-\" + (months % 12); // \"1-1\"\nCalendarInterval i = CalendarInterval.fromYearMonthString(s);","handlingStrategy":"validation","validationCode":"long months = Long.parseLong(monthPart);\nif (months < 0 || months > 11) throw new IllegalArgumentException(\"month \" + months + \" outside range [0, 11]\");\nCalendarInterval i = CalendarInterval.fromYearMonthString(year + \"-\" + month);","typeGuard":"boolean inRange(long v, long min, long max) { return v >= min && v <= max; }","tryCatchPattern":"try { CalendarInterval i = CalendarInterval.fromYearMonthString(s); } catch (IllegalArgumentException e) { log.warn(\"bad interval \" + s + \": \" + e.getMessage()); }","preventionTips":["Normalize interval components (carry month 13 into years+1 month 1)","Validate each field against its range before string construction","Regexp the 'y-m' shape before parsing","Catch IllegalArgumentException at the user-input boundary"],"tags":["java","interval","parsing","range-validation"],"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"}