{"record":{"id":"2ff036eadf5cb70e","repo":"apache/flink","slug":"workaround-hack","errorCode":null,"errorMessage":"Workaround hack.","messagePattern":"Workaround hack\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/api/common/typeutils/TypeComparator.java","lineNumber":317,"sourceCode":"     */\n    public abstract int extractKeys(Object record, Object[] target, int index);\n\n    /**\n     * Get the field comparators. This is used together with {@link #extractKeys(Object, Object[],\n     * int)} to provide interoperability between different record types. Note, that this should\n     * return at least one Comparator and that the number of Comparators must match the number of\n     * extracted keys.\n     *\n     * @return An Array of Comparators for the extracted keys.\n     */\n    @SuppressWarnings(\"rawtypes\")\n    public abstract TypeComparator[] getFlatComparators();\n\n    // --------------------------------------------------------------------------------------------\n\n    @SuppressWarnings(\"rawtypes\")\n    public int compareAgainstReference(Comparable[] keys) {\n        throw new UnsupportedOperationException(\"Workaround hack.\");\n    }\n}\n","sourceCodeStart":299,"sourceCodeEnd":320,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/api/common/typeutils/TypeComparator.java#L299-L320","documentation":"Thrown by the default implementation of TypeComparator.compareAgainstReference(Comparable[] keys). This method is a stub ('workaround hack') that is not implemented by the base TypeComparator class. Only specific subclasses that need reference-comparison semantics override it; calling it on a comparator that does not override it always fails. It is an internal API not intended for direct user invocation.","triggerScenarios":"Calling compareAgainstReference on a TypeComparator instance whose concrete subclass did not override the method. This happens in internal Flink runtime paths (e.g. certain sort or hash-join probe mechanics) when the comparator type does not support reference-based comparison, or when custom operator code inadvertently calls this internal method.","commonSituations":"Writing a custom operator that directly uses a TypeComparator and calls compareAgainstReference without checking whether the concrete type supports it. A Flink internal code path that selects the wrong comparator variant for a join or sort. Unlikely to be hit by application-level DataStream/Table API users.","solutions":["Do not call compareAgainstReference directly; it is an internal method.","If writing a custom TypeComparator subclass that needs reference comparison, override compareAgainstReference with a real implementation.","Use the standard extractKeys + getFlatComparators path for cross-type key comparison instead."],"exampleFix":"// before — calling the unimplemented stub\nint cmp = myComparator.compareAgainstReference(keys); // throws\n\n// after — override in your custom comparator, or use the flat-comparator API\npublic class MyComparator extends TypeComparator<MyType> {\n    @Override\n    public int compareAgainstReference(Comparable[] keys) {\n        // real implementation\n        return keys[0].compareTo(reference);\n    }\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    int cmp = comparator.compareAgainstReference(keys);\n} catch (UnsupportedOperationException e) {\n    // this comparator does not support reference comparison; use extractKeys + getFlatComparators\n}","preventionTips":["Treat TypeComparator.compareAgainstReference as internal; do not call it from user code.","If writing a custom comparator that needs reference comparison, override the method with a real implementation.","Prefer the extractKeys / getFlatComparators API for cross-type key comparison."],"tags":["comparator","internal-api","unsupported-operation"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}