{"record":{"id":"f962acb6e5d2fb10","repo":"prestodb/presto","slug":"invalid-interval-qualifier-to","errorCode":null,"errorMessage":"Invalid interval qualifier:  to ","messagePattern":"Invalid interval qualifier:  to ","errorType":"error_code","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/util/DateTimeUtils.java","lineNumber":593,"sourceCode":"\n        List<PeriodParser> parsers = new ArrayList<>();\n\n        PeriodFormatterBuilder builder = new PeriodFormatterBuilder();\n        switch (startField) {\n            case YEAR:\n                builder.appendYears();\n                parsers.add(builder.toParser());\n                if (endField == IntervalField.YEAR) {\n                    break;\n                }\n                builder.appendLiteral(\"-\");\n                // fall through\n\n            case MONTH:\n                builder.appendMonths();\n                parsers.add(builder.toParser());\n                if (endField != IntervalField.MONTH) {\n                    throw new IllegalArgumentException(\"Invalid interval qualifier: \" + startField + \" to \" + endField);\n                }\n                break;\n\n            case DAY:\n                builder.appendDays();\n                parsers.add(builder.toParser());\n                if (endField == IntervalField.DAY) {\n                    break;\n                }\n                builder.appendLiteral(\" \");\n                // fall through\n\n            case HOUR:\n                builder.appendHours();\n                parsers.add(builder.toParser());\n                if (endField == IntervalField.HOUR) {\n                    break;\n                }","sourceCodeStart":575,"sourceCodeEnd":611,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/util/DateTimeUtils.java#L575-L611","documentation":"cretePeriodFormatter builds a Joda PeriodFormatter for a DAY–SECOND interval qualifier range. While appending fields in order (HOURS→MINUTES→SECONDS per branch), if the endField does not legally follow the current startField (e.g. endField is not MONTH when starting at MONTH in the year-month variant, or fields out of order), the builder aborts with this IllegalArgumentException.","triggerScenarios":"Static initialization of the INTERVAL_*_FORMATTER constants with an illegal (startField, endField) pair — e.g. INTERVAL_HOUR_SECOND_FORMATTER built with end earlier than start, or a new formatter constant added with fields in the wrong order. Since it runs in static initializers, it surfaces as ExceptionInInitializerError at class-load time.","commonSituations":"Developers adding a new interval formatter constant with swapped or non-contiguous fields; refactoring IntervalField enum ordering; backporting patches that change field hierarchy assumptions.","solutions":["Check the (startField, endField) arguments passed to each INTERVAL_*_FORMATTER static initializer — end must be the same field or the next sub-field in the hierarchy","Fix the enum order or the switch statement so fields are appended in strict order HOUR→MINUTE→SECOND (or YEAR→MONTH)","After fixing, verify DateTimeUtils class loads (any test touching date parsing will exercise the static block)","Add a unit test enumerating all legal qualifier pairs to catch regressions at init time"],"exampleFix":"// before\nnew IntervalFormatter(IntervalField.SECOND, IntervalField.HOUR, ...) // end before start\n// after\nnew IntervalFormatter(IntervalField.HOUR, IntervalField.SECOND, ...)","handlingStrategy":"try-catch","validationCode":"// static-init failure: verify class loads early\ntry { Class.forName(\"com.facebook.presto.util.DateTimeUtils\"); } catch (ExceptionInInitializerError e) { throw new IllegalStateException(\"DateTimeUtils formatter init failed\", e); }","typeGuard":null,"tryCatchPattern":"try { INTERVAL_X_FORMATTER = cretePeriodFormatter(start, end); } catch (IllegalArgumentException e) { throw new IllegalStateException(\"Bad interval qualifier \" + start + \" to \" + end, e); }","preventionTips":["Keep formatter field pairs contiguous and ordered (HOUR<MINUTE<SECOND, YEAR<MONTH)","Add a unit test that builds formatters for every legal qualifier pair","Run any DateTimeUtils-touching test after touching IntervalField or formatter constants"],"tags":["presto","interval","static-initialization","datetime"],"backgroundTag":"invalid-interval-qualifier","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"}