{"record":{"id":"ef1eb5acc0c34023","repo":"apache/flink","slug":"tuple0-cannot-take-any-data-as-it-has-zero-fields","errorCode":null,"errorMessage":"Tuple0 cannot take any data, as it has zero fields.","messagePattern":"Tuple0 cannot take any data, as it has zero fields\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/api/java/typeutils/runtime/Tuple0Serializer.java","lineNumber":57,"sourceCode":"    // ------------------------------------------------------------------------\n\n    @Override\n    public Tuple0Serializer duplicate() {\n        return this;\n    }\n\n    @Override\n    public Tuple0 createInstance() {\n        return Tuple0.INSTANCE;\n    }\n\n    @Override\n    public Tuple0 createInstance(Object[] fields) {\n        if (fields == null || fields.length == 0) {\n            return Tuple0.INSTANCE;\n        }\n\n        throw new UnsupportedOperationException(\n                \"Tuple0 cannot take any data, as it has zero fields.\");\n    }\n\n    @Override\n    public Tuple0 copy(Tuple0 from) {\n        return from;\n    }\n\n    @Override\n    public Tuple0 copy(Tuple0 from, Tuple0 reuse) {\n        return reuse;\n    }\n\n    @Override\n    public int getLength() {\n        return 1;\n    }\n","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/api/java/typeutils/runtime/Tuple0Serializer.java#L39-L75","documentation":"Tuple0Serializer is the serializer for the zero-arity Tuple0 type. createInstance(Object[] fields) rejects any attempt to initialize a Tuple0 with field values, because Tuple0 has no fields at all: an empty array (or null) yields Tuple0.INSTANCE, anything else throws UnsupportedOperationException. It signals a programming error where field data was routed to a zero-arity tuple type.","triggerScenarios":"Calling Tuple0Serializer.createInstance(Object[]) with a non-empty array; e.g. building a projection/operator that feeds N field values into a Tuple-typed output whose TypeInformation resolved to Tuple0 (arity 0), or reflection-based field-copy utilities that pass a source record's fields into a Tuple0 target.","commonSituations":"Projection that selects zero columns but still passes the original field array downstream. Type erasure/generic misuse where the expected Tuple2 got replaced by Tuple0. Code that uniformly does serializer.createInstance(recordFields) across tuple arities and hits arity 0. Pojo-to-Tuple conversion with an empty field list.","solutions":["Guard before calling: if the target serializer is Tuple0Serializer (arity == 0), pass an empty array (or just use Tuple0.INSTANCE) instead of the source fields.","Fix the upstream projection/type so that the tuple arity matches the number of fields being supplied; Tuple0 should only appear when there is genuinely no data.","In generic field-copy code, branch on tuple arity: arity 0 -> Tuple0.INSTANCE, otherwise createInstance(fields)."],"exampleFix":"// before\nObject[] fields = new Object[] { \"leftover\" };\nTuple0 t = (Tuple0) tuple0Serializer.createInstance(fields); // throws 686\n\n// after\nObject[] fields = new Object[0]; // or: Tuple0 t = Tuple0.INSTANCE;\nTuple0 t = (Tuple0) tuple0Serializer.createInstance(fields);","handlingStrategy":"type-guard","validationCode":"Object[] fieldsForTuple0 = (tupleSerializer.getArity() == 0) ? new Object[0] : fields;\nTuple0 t = (Tuple0) tupleSerializer.createInstance(fieldsForTuple0);","typeGuard":"public static boolean isTuple0Serializer(TupleSerializer<?> s) {\n    return s.getArity() == 0;\n}","tryCatchPattern":"try {\n    return ser.createInstance(fields);\n} catch (UnsupportedOperationException e) {\n    if (ser.getArity() == 0) return (T) Tuple0.INSTANCE; // arity 0 carries no data\n    throw e;\n}","preventionTips":["Branch on serializer.getArity() before createInstance(Object[]) in generic code.","For arity-0 types use Tuple0.INSTANCE directly.","Ensure projections that select zero columns do not forward source field arrays."],"tags":["tuple","arity-mismatch","misuse","typeutils"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}