{"record":{"id":"40345441a6bf722d","repo":"MyCATApache/Mycat-Server","slug":"interval-s-string-was-null","errorCode":null,"errorMessage":"Interval %s string was null","messagePattern":"Interval (.+?) string was null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/memory/unsafe/types/CalendarInterval.java","lineNumber":172,"sourceCode":"        // 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));\n      } catch (Exception e) {\n        throw new IllegalArgumentException(\n          \"Error parsing interval day-time string: \" + e.getMessage(), e);\n      }\n    }\n    return result;\n  }\n\n  public static CalendarInterval fromSingleUnitString(String unit, String s)\n      throws IllegalArgumentException {\n\n    CalendarInterval result = null;\n    if (s == null) {\n      throw new IllegalArgumentException(String.format(\"Interval %s string was null\", unit));\n    }\n    s = s.trim();\n    Matcher m = quoteTrimPattern.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        if (unit.equals(\"year\")) {\n          int year = (int) toLongWithRange(\"year\", m.group(1),\n            Integer.MIN_VALUE / 12, Integer.MAX_VALUE / 12);\n          result = new CalendarInterval(year * 12, 0L);\n\n        } else if (unit.equals(\"month\")) {\n          int month = (int) toLongWithRange(\"month\", m.group(1),\n            Integer.MIN_VALUE, Integer.MAX_VALUE);\n          result = new CalendarInterval(month, 0L);\n","sourceCodeStart":154,"sourceCodeEnd":190,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/memory/unsafe/types/CalendarInterval.java#L154-L190","documentation":"fromSingleUnitString(unit, s) parses a single-unit interval like '3' with unit 'year' or 'month'. This IllegalArgumentException is thrown when the value string s is null; the offending unit name is included in the message.","triggerScenarios":"Calling CalendarInterval.fromSingleUnitString(\"month\", null), typically when the SQL INTERVAL ... clause has no value or a config value is unset.","commonSituations":"Missing interval literal in generated SQL, null property/parameter fed into the parser.","solutions":["Ensure a non-null value string is passed for the unit","Default the value (e.g. \"0\") when absent before calling","Catch IllegalArgumentException and treat null input as a distinct error path"],"exampleFix":"// before\nCalendarInterval iv = CalendarInterval.fromSingleUnitString(\"month\", stmt.getValue());\n// after\nString v = stmt.getValue();\nCalendarInterval iv = CalendarInterval.fromSingleUnitString(\"month\", v == null ? \"0\" : v);","handlingStrategy":"type-guard","validationCode":"static String requireSingleUnitValue(String unit, String s) {\n  if (s == null || s.trim().isEmpty()) throw new IllegalArgumentException(\"value for unit \" + unit + \" required\");\n  return s.trim();\n}","typeGuard":"static boolean hasSingleUnitValue(String s) {\n  return s != null && !s.trim().isEmpty();\n}","tryCatchPattern":"try {\n  iv = CalendarInterval.fromSingleUnitString(unit, s);\n} catch (IllegalArgumentException e) {\n  log.error(\"Null/invalid value for interval unit {}: {}\", unit, e.getMessage());\n  iv = CalendarInterval.ZERO;\n}","preventionTips":["Default missing values to \"0\" before parsing","Never pass SQL AST values straight through without null checks","Log the unit alongside the failure for diagnosis"],"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"}