{"record":{"id":"a02a2ce38303b9bc","repo":"prestodb/presto","slug":"invalid-year-month-interval","errorCode":null,"errorMessage":"Invalid year-month interval: ","messagePattern":"Invalid year-month interval: ","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"presto-client/src/main/java/com/facebook/presto/client/IntervalYearMonth.java","lineNumber":71,"sourceCode":"\n        return format(\"%s%d-%d\", sign, months / 12, months % 12);\n    }\n\n    public static int parseMonths(String value)\n    {\n        if (value.equals(INT_MIN_VALUE)) {\n            return Integer.MIN_VALUE;\n        }\n\n        int signum = 1;\n        if (value.startsWith(\"-\")) {\n            signum = -1;\n            value = value.substring(1);\n        }\n\n        Matcher matcher = FORMAT.matcher(value);\n        if (!matcher.matches()) {\n            throw new IllegalArgumentException(\"Invalid year-month interval: \" + value);\n        }\n\n        int years = parseInt(matcher.group(1));\n        int months = parseInt(matcher.group(2));\n\n        return toMonths(years, months) * signum;\n    }\n}\n","sourceCodeStart":53,"sourceCodeEnd":80,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-client/src/main/java/com/facebook/presto/client/IntervalYearMonth.java#L53-L80","documentation":"IntervalYearMonth.parseMonths parses a year-month interval string (e.g. '1-6') using the FORMAT regex. If the string does not match the '<years>-<months>' shape, this IllegalArgumentException is thrown with the offending value appended to the message.","triggerScenarios":"Calling IntervalYearMonth.parseMonths with strings like '18 months', '1y6m', a day-time string such as '1 12:00:00.000', or values with wrong separator (e.g. '1:6' instead of '1-6') that fail the FORMAT regex.","commonSituations":"Mixing up the two interval types (passing day-time syntax to the year-month parser); constructing intervals from user input without format validation; values taken from logs or other systems with different interval notations.","solutions":["Check the input matches '<years>-<months>' (optionally signed, e.g. '-1-6').","Normalize before parsing: convert '18 months' style input to years/months form like '1-6' yourself.","Wrap parseMonths in try-catch and show the expected format in the error message.","Route day-time interval strings to IntervalDayTime.parseMillis instead."],"exampleFix":"// before\nint months = IntervalYearMonth.parseMonths(userInput); // throws on '1y6m'\n// after\nMatcher m = Pattern.compile(\"(-?)(\\\\d+)-(\\\\d+)\").matcher(userInput.trim());\nif (!m.matches()) { throw new IllegalArgumentException(\"Expected format: years-months, e.g. 1-6\"); }\nint months = IntervalYearMonth.parseMonths(m.group(1) + m.group(2) + \"-\" + m.group(3));","handlingStrategy":"validation","validationCode":"private static final Pattern INTERVAL_YEAR_MONTH = Pattern.compile(\"-?\\\\d+-\\\\d+\");\nif (value == null || !INTERVAL_YEAR_MONTH.matcher(value.trim()).matches()) {\n    throw new IllegalArgumentException(\"Expected year-month interval like '1-6', got: \" + value);\n}","typeGuard":null,"tryCatchPattern":"try { int months = IntervalYearMonth.parseMonths(value); } catch (IllegalArgumentException e) { /* surface expected 'years-months' format */ }","preventionTips":["Check the '<years>-<months>' shape before calling parseMonths","Route day-time strings to IntervalDayTime instead","Normalize textual input ('18 months') into numeric form first","Centralize interval parsing with pre-validation"],"tags":["parsing","presto-client","illegal-argument","interval"],"backgroundTag":"invalid-interval-format","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}