{"record":{"id":"24136e50bd6c20aa","repo":"MyCATApache/Mycat-Server","slug":"interval-day-time-string-was-null","errorCode":null,"errorMessage":"Interval day-time string was null","messagePattern":"Interval day-time string was null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/memory/unsafe/types/CalendarInterval.java","lineNumber":140,"sourceCode":"        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);\n    if (!m.matches()) {\n      throw new IllegalArgumentException(\n        \"Interval string does not match day-time format of 'd h:m:s.n': \" + s);\n    } else {\n      try {\n        int sign = m.group(1) != null && m.group(1).equals(\"-\") ? -1 : 1;\n        long days = toLongWithRange(\"day\", m.group(2), 0, Integer.MAX_VALUE);\n        long hours = toLongWithRange(\"hour\", m.group(3), 0, 23);\n        long minutes = toLongWithRange(\"minute\", m.group(4), 0, 59);\n        long seconds = toLongWithRange(\"second\", m.group(5), 0, 59);\n        // Hive allow nanosecond precision interval\n        long nanos = toLongWithRange(\"nanosecond\", m.group(7), 0L, 999999999L);\n        result = new CalendarInterval(0, sign * (\n          days * MICROS_PER_DAY + hours * MICROS_PER_HOUR + minutes * MICROS_PER_MINUTE +\n          seconds * MICROS_PER_SECOND + nanos / 1000L));","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/memory/unsafe/types/CalendarInterval.java#L122-L158","documentation":"Thrown by CalendarInterval.fromDayTimeString when the caller passes a null string instead of a day-time interval literal. It is a fail-fast null guard at the top of the parse method; any string input (even empty or malformed) passes this check and is handled later, so the error fires only when s == null. Callers should validate non-null input before parsing, e.g. reject empty connection-string interval parameters upstream.","triggerScenarios":"Calling CalendarInterval.fromDayTimeString(null) directly, or passing a null column/config value through to the parser without a null check.","commonSituations":"Unset configuration properties, NULL values from upstream ETL passed into interval parsing, missing query literal.","solutions":["Check for null before calling fromDayTimeString and substitute a default or reject the input","Ensure the SQL literal/config value is actually set (not NULL/empty)","Catch IllegalArgumentException and handle the null-input case explicitly"],"exampleFix":"// before\nCalendarInterval iv = CalendarInterval.fromDayTimeString(cfg.get(\"interval\"));\n// after\nString s = cfg.get(\"interval\");\nif (s == null || s.trim().isEmpty()) { throw new IllegalArgumentException(\"interval config is required\"); }\nCalendarInterval iv = CalendarInterval.fromDayTimeString(s);","handlingStrategy":"type-guard","validationCode":"static String requireNonNullInterval(String s) {\n  if (s == null || s.trim().isEmpty()) throw new IllegalArgumentException(\"interval value required\");\n  return s.trim();\n}","typeGuard":"static boolean isParseableInterval(String s) {\n  return s != null && !s.trim().isEmpty();\n}","tryCatchPattern":"try {\n  iv = CalendarInterval.fromDayTimeString(s);\n} catch (IllegalArgumentException e) {\n  if (s == null) { iv = CalendarInterval.ZERO; } else throw e;\n}","preventionTips":["Null-check all config/column values before interval parsing","Substitute a default interval for missing values","Reject empty strings early, they fail the regex anyway"],"tags":["java","null","interval","illegal-argument"],"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"}