{"record":{"id":"e29c72557c1e8c0b","repo":"apache/flink","slug":"could-not-initialize-comparator","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/LocalTimeTypeInfo.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    public static LocalTimeTypeInfo getInfoFor(Class type) {\n        checkNotNull(type);\n\n        if (type == LocalDate.class) {\n            return LOCAL_DATE;\n        } else if (type == LocalTime.class) {\n            return LOCAL_TIME;\n        } else if (type == LocalDateTime.class) {\n            return LOCAL_DATE_TIME;\n        }\n        return null;\n    }\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/LocalTimeTypeInfo.java#L144-L180","documentation":"LocalTimeTypeInfo.instantiateComparator reflectively builds the java.time (LocalDate/LocalTime/LocalDateTime) comparator via comparatorClass.getConstructor(boolean.class).newInstance(ascending). If the comparator class lacks the required public boolean constructor or instantiation otherwise fails, a RuntimeException names the comparator class. This mirrors BasicTypeInfo/SqlTimeTypeInfo but is specific to the java.time type family.","triggerScenarios":"A custom LocalTimeTypeInfo with a comparatorClass missing the (boolean) constructor; reflective access blocked by JDK module settings; comparator class made abstract or interface by mistake in a fork.","commonSituations":"Forking Flink and altering the LocalTime comparator classes; running under a strict module path that blocks reflective construction; classpath corruption loading a partial comparator class.","solutions":["Ensure the comparator class for java.time types exposes a public constructor taking a single boolean.","Avoid overriding LocalTimeTypeInfo/comparator classes in a fork; rely on the built-in implementations.","On restricted JDKs, add the appropriate --add-opens to allow reflective access to the comparator package."],"exampleFix":"// before: custom comparator missing boolean constructor\n\n// after: use built-in LocalTimeTypeInfo.INFO_FOR LocalDate/LocalTime/LocalDateTime;\n// or ensure comparator has: 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 LocalTimeTypeInfo.instantiateComparator(clazz, asc);\n} catch (RuntimeException e) {\n    throw new IllegalStateException(\n        \"LocalTime comparator \" + clazz + \" misconfigured\", e);\n}","preventionTips":["Use the built-in LocalTimeTypeInfo for LocalDate/LocalTime/LocalDateTime.","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","java-time"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}