{"record":{"id":"d64a50e5594a5993","repo":"MyCATApache/Mycat-Server","slug":"error-parsing-interval-string","errorCode":null,"errorMessage":"Error parsing interval string: ","messagePattern":"Error parsing interval string: ","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/memory/unsafe/types/CalendarInterval.java","lineNumber":225,"sourceCode":"          long minute = toLongWithRange(\"minute\", m.group(1),\n            Long.MIN_VALUE / MICROS_PER_MINUTE, Long.MAX_VALUE / MICROS_PER_MINUTE);\n          result = new CalendarInterval(0, minute * MICROS_PER_MINUTE);\n\n        } else if (unit.equals(\"second\")) {\n          long micros = parseSecondNano(m.group(1));\n          result = new CalendarInterval(0, micros);\n\n        } else if (unit.equals(\"millisecond\")) {\n          long millisecond = toLongWithRange(\"millisecond\", m.group(1),\n                  Long.MIN_VALUE / MICROS_PER_MILLI, Long.MAX_VALUE / MICROS_PER_MILLI);\n          result = new CalendarInterval(0, millisecond * MICROS_PER_MILLI);\n\n        } else if (unit.equals(\"microsecond\")) {\n          long micros = Long.parseLong(m.group(1));\n          result = new CalendarInterval(0, micros);\n        }\n      } catch (Exception e) {\n        throw new IllegalArgumentException(\"Error parsing interval string: \" + e.getMessage(), e);\n      }\n    }\n    return result;\n  }\n\n  /**\n   * Parse second_nano string in ss.nnnnnnnnn format to microseconds\n   */\n  public static long parseSecondNano(String secondNano) throws IllegalArgumentException {\n    String[] parts = secondNano.split(\"\\\\.\");\n    if (parts.length == 1) {\n      return toLongWithRange(\"second\", parts[0], Long.MIN_VALUE / MICROS_PER_SECOND,\n        Long.MAX_VALUE / MICROS_PER_SECOND) * MICROS_PER_SECOND;\n\n    } else if (parts.length == 2) {\n      long seconds = parts[0].equals(\"\") ? 0L : toLongWithRange(\"second\", parts[0],\n        Long.MIN_VALUE / MICROS_PER_SECOND, Long.MAX_VALUE / MICROS_PER_SECOND);\n      long nanos = toLongWithRange(\"nanosecond\", parts[1], 0L, 999999999L);","sourceCodeStart":207,"sourceCodeEnd":243,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/memory/unsafe/types/CalendarInterval.java#L207-L243","documentation":"fromSingleUnitString throws this IllegalArgumentException when the numeric value parses but fails toLongWithRange checks or Long.parseLong (e.g. for 'microsecond'). The original exception is attached as cause.","triggerScenarios":"Value out of the allowed range for the unit, e.g. fromSingleUnitString(\"year\", \"999999999999\") (year limited to Integer.MAX_VALUE/12), or a huge microsecond value overflowing long parse/conversion.","commonSituations":"Very large interval literals in SQL, values generated without range clamping, copy-pasted durations from other systems.","solutions":["Reduce the value or express it in a larger unit so it fits the allowed range","Keep year values within +/- Integer.MAX_VALUE/12","Catch the exception and read getCause().getMessage() for the failing field"],"exampleFix":"// before\nCalendarInterval iv = CalendarInterval.fromSingleUnitString(\"year\", \"999999999999\");\n// after\nCalendarInterval iv = CalendarInterval.fromSingleUnitString(\"year\", \"178956970\"); // Integer.MAX_VALUE/12","handlingStrategy":"validation","validationCode":"static void requireInRange(String unit, String s) {\n  long v = Long.parseLong(s.trim());\n  if (unit.equals(\"year\") && Math.abs(v) > Integer.MAX_VALUE / 12L)\n    throw new IllegalArgumentException(\"year value too large: \" + v);\n}","typeGuard":null,"tryCatchPattern":"try {\n  iv = CalendarInterval.fromSingleUnitString(unit, s);\n} catch (IllegalArgumentException e) {\n  throw new IllegalArgumentException(\"Interval value \" + s + \" out of range for \" + unit, e.getCause());\n}","preventionTips":["Clamp or rescale large values into a bigger unit before parsing","Keep year magnitudes under Integer.MAX_VALUE/12","Read the cause message to learn the allowed 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"}