{"record":{"id":"85b7a09f34397cc6","repo":"apache/flink","slug":"tuple-size-must-be-greater-than-0-size-type-get","errorCode":null,"errorMessage":"Tuple size must be greater than 0. Size: {type.getArity()}","messagePattern":"Tuple size must be greater than 0\\. Size: (.+?)","errorType":"exception","errorClass":"InvalidProgramException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/api/common/operators/Keys.java","lineNumber":246,"sourceCode":"            this(new int[] {keyPosition}, type, false);\n        }\n\n        /** Create int-based (non-nested) field position keys on a tuple type. */\n        public ExpressionKeys(int[] keyPositions, TypeInformation<T> type) {\n            this(keyPositions, type, false);\n        }\n\n        /** Create int-based (non-nested) field position keys on a tuple type. */\n        public ExpressionKeys(int[] keyPositions, TypeInformation<T> type, boolean allowEmpty) {\n\n            if (!type.isTupleType() || !(type instanceof CompositeType)) {\n                throw new InvalidProgramException(\n                        \"Specifying keys via field positions is only valid \"\n                                + \"for tuple data types. Type: \"\n                                + type);\n            }\n            if (type.getArity() == 0) {\n                throw new InvalidProgramException(\n                        \"Tuple size must be greater than 0. Size: \" + type.getArity());\n            }\n            if (!allowEmpty && (keyPositions == null || keyPositions.length == 0)) {\n                throw new IllegalArgumentException(\"The grouping fields must not be empty.\");\n            }\n\n            this.keyFields = new ArrayList<>();\n\n            if (keyPositions == null || keyPositions.length == 0) {\n                // use all tuple fields as key fields\n                keyPositions = createIncrIntArray(type.getArity());\n            } else {\n                rangeCheckFields(keyPositions, type.getArity() - 1);\n            }\n\n            checkArgument(\n                    keyPositions.length > 0, \"Grouping fields can not be empty at this point\");\n","sourceCodeStart":228,"sourceCodeEnd":264,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/api/common/operators/Keys.java#L228-L264","documentation":"Thrown by ExpressionKeys(int[], TypeInformation, boolean) when the tuple type reports arity 0. A tuple with zero fields cannot provide any key position; the constructor rejects it because there is nothing to key on.","triggerScenarios":"Constructing ExpressionKeys against a Tuple0 type (e.g. Tuple0/Unit from Scala interop, or a degenerate case TypeInfo reporting arity 0); passing a custom CompositeType whose getArity() returns 0.","commonSituations":"Scala/Java interop producing a Unit/Tuple0 stream then trying to key it; programmatically-built TypeInformation that erroneously reports zero arity; tests with placeholder tuple types.","solutions":["Avoid keying on a zero-arity tuple; restructure the upstream to emit a real key field.","If the type is a placeholder, replace it with a tuple that has at least one field.","Validate type.getArity() > 0 before building position-based keys."],"exampleFix":"// before\nDataSet<Tuple0> ds = ...;\nds.groupBy(0);\n// after\nDataSet<Tuple1<String>> ds = upstream.map(x -> Tuple1.of(x.id));\nds.groupBy(0);","handlingStrategy":"validation","validationCode":"if (type.getArity() == 0) {\n    throw new IllegalArgumentException(\"Tuple type has arity 0; cannot build position keys: \" + type);\n}","typeGuard":"static <T> boolean hasFields(TypeInformation<T> t) { return t.getArity() > 0; }","tryCatchPattern":null,"preventionTips":["Do not key on zero-arity tuples (Tuple0/Unit); emit a real key field upstream.","Validate arity > 0 before constructing position-based ExpressionKeys.","Avoid placeholder TypeInformation in tests that reports zero fields."],"tags":["flink-core","keys","expression-keys","tuple","validation"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}