{"record":{"id":"ca92efbb36924846","repo":"apache/flink","slug":"could-not-initialize-primitive-array-comparator","errorCode":null,"errorMessage":"Could not initialize primitive {} array comparator.","messagePattern":"Could not initialize primitive (.+?) array comparator\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/api/common/typeinfo/PrimitiveArrayTypeInfo.java","lineNumber":273,"sourceCode":"    static {\n        TYPES.put(boolean[].class, BOOLEAN_PRIMITIVE_ARRAY_TYPE_INFO);\n        TYPES.put(byte[].class, BYTE_PRIMITIVE_ARRAY_TYPE_INFO);\n        TYPES.put(short[].class, SHORT_PRIMITIVE_ARRAY_TYPE_INFO);\n        TYPES.put(int[].class, INT_PRIMITIVE_ARRAY_TYPE_INFO);\n        TYPES.put(long[].class, LONG_PRIMITIVE_ARRAY_TYPE_INFO);\n        TYPES.put(float[].class, FLOAT_PRIMITIVE_ARRAY_TYPE_INFO);\n        TYPES.put(double[].class, DOUBLE_PRIMITIVE_ARRAY_TYPE_INFO);\n        TYPES.put(char[].class, CHAR_PRIMITIVE_ARRAY_TYPE_INFO);\n    }\n\n    @Override\n    @PublicEvolving\n    public PrimitiveArrayComparator<T, ?> createComparator(\n            boolean sortOrderAscending, ExecutionConfig executionConfig) {\n        try {\n            return comparatorClass.getConstructor(boolean.class).newInstance(sortOrderAscending);\n        } catch (Exception e) {\n            throw new RuntimeException(\n                    \"Could not initialize primitive \"\n                            + comparatorClass.getName()\n                            + \" array comparator.\",\n                    e);\n        }\n    }\n}\n","sourceCodeStart":255,"sourceCodeEnd":281,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/api/common/typeinfo/PrimitiveArrayTypeInfo.java#L255-L281","documentation":"PrimitiveArrayTypeInfo.createComparator reflectively instantiates the PrimitiveArrayComparator via comparatorClass.getConstructor(boolean.class).newInstance(ascending). If the comparator class lacks the required public boolean constructor or instantiation throws, a RuntimeException names the comparator class with the 'primitive array comparator' suffix. This is an internal contract: each primitive-array comparator must expose that constructor.","triggerScenarios":"A custom PrimitiveArrayTypeInfo with a comparatorClass missing the (boolean) constructor; reflective access blocked; comparator class made abstract or otherwise non-instantiable in a fork.","commonSituations":"Forking Flink and altering primitive-array comparators; JDK module restrictions blocking reflective construction; classpath issues loading a partial comparator implementation.","solutions":["Ensure any custom primitive-array comparator class has a public constructor taking a single boolean.","Use the built-in PrimitiveArrayTypeInfo instances rather than custom ones.","On restricted JDKs, add the appropriate --add-opens so reflection into the comparator constructor succeeds."],"exampleFix":"// before: custom comparator lacks boolean constructor\n\n// after: ensure public constructor\npublic class MyIntArrayComparator extends PrimitiveArrayComparator<Integer, IntComparator> {\n    public MyIntArrayComparator(boolean ascending) { super(ascending); }\n}","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 PrimitiveArrayComparator<?,?>> c) {\n    try { c.getConstructor(boolean.class); return true; }\n    catch (NoSuchMethodException e) { return false; }\n}","tryCatchPattern":"try {\n    return ti.createComparator(asc, cfg);\n} catch (RuntimeException e) {\n    throw new IllegalStateException(\n        \"Primitive array comparator misconfigured: \" + comparatorClass, e);\n}","preventionTips":["Use the built-in PrimitiveArrayTypeInfo instances.","Ensure custom primitive-array comparators expose a public (boolean) constructor.","Add a reflection test if forking comparator classes."],"tags":["type-information","comparator","reflection","primitive-array"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}