{"record":{"id":"e6dbf220e50e1dd5","repo":"apache/flink","slug":"could-not-initialize-comparator-e6dbf2","errorCode":null,"errorMessage":"Could not initialize comparator {}","messagePattern":"Could not initialize comparator (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/api/common/typeinfo/SqlTimeTypeInfo.java","lineNumber":162,"sourceCode":"            return false;\n        }\n    }\n\n    @Override\n    public String toString() {\n        return clazz.getSimpleName();\n    }\n\n    // --------------------------------------------------------------------------------------------\n\n    private static <X> TypeComparator<X> instantiateComparator(\n            Class<? extends TypeComparator<X>> comparatorClass, boolean ascendingOrder) {\n        try {\n            Constructor<? extends TypeComparator<X>> constructor =\n                    comparatorClass.getConstructor(boolean.class);\n            return constructor.newInstance(ascendingOrder);\n        } catch (Exception e) {\n            throw new RuntimeException(\n                    \"Could not initialize comparator \" + comparatorClass.getName(), e);\n        }\n    }\n\n    @SuppressWarnings(\"unchecked\")\n    public static <X> SqlTimeTypeInfo<X> getInfoFor(Class<X> type) {\n        checkNotNull(type);\n\n        if (type == Date.class) {\n            return (SqlTimeTypeInfo<X>) DATE;\n        } else if (type == Time.class) {\n            return (SqlTimeTypeInfo<X>) TIME;\n        } else if (type == Timestamp.class) {\n            return (SqlTimeTypeInfo<X>) TIMESTAMP;\n        }\n        return null;\n    }\n}","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/api/common/typeinfo/SqlTimeTypeInfo.java#L144-L180","documentation":"SqlTimeTypeInfo.instantiateComparator reflectively builds the SQL-time comparator (Date, Time, Timestamp) via comparatorClass.getConstructor(boolean.class).newInstance(ascending). If the comparator class lacks the public boolean constructor or instantiation fails, a RuntimeException names the comparator class. This is the same reflection contract as BasicTypeInfo/LocalTimeTypeInfo, applied to java.sql time types.","triggerScenarios":"A custom SqlTimeTypeInfo with a comparatorClass missing the (boolean) constructor; reflective access blocked by JDK settings; comparator class corrupted or abstract in a forked build.","commonSituations":"Forking Flink and altering the SQL-time comparators; strict module path blocking reflective construction; classpath corruption loading a partial comparator class; migrating between JDK versions that tighten reflection.","solutions":["Ensure the comparator class for SQL-time types exposes a public constructor accepting a single boolean.","Avoid overriding SqlTimeTypeInfo/comparator classes; rely on the built-in implementations.","On restricted JDKs, add the appropriate --add-opens for the comparator package."],"exampleFix":"// before: custom comparator missing boolean constructor\n\n// after: use built-in SqlTimeTypeInfo for Date/Time/Timestamp;\n// or ensure: public MyComparator(boolean ascending) { ... }","handlingStrategy":"type-guard","validationCode":"try {\n    comparatorClass.getConstructor(boolean.class);\n} catch (NoSuchMethodException e) {\n    throw new IllegalStateException(\n        comparatorClass + \" must have a public (boolean) constructor\", e);\n}","typeGuard":"static boolean hasBooleanCtor(Class<? extends TypeComparator<?>> c) {\n    try { c.getConstructor(boolean.class); return true; }\n    catch (NoSuchMethodException e) { return false; }\n}","tryCatchPattern":"try {\n    return SqlTimeTypeInfo.instantiateComparator(clazz, asc);\n} catch (RuntimeException e) {\n    throw new IllegalStateException(\n        \"SqlTime comparator \" + clazz + \" misconfigured\", e);\n}","preventionTips":["Use the built-in SqlTimeTypeInfo for Date/Time/Timestamp.","If forking, add a reflection test for the comparator's boolean constructor.","On strict JDKs, add --add-opens for the comparator package."],"tags":["type-information","comparator","reflection","sql-time"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}