{"record":{"id":"7de3446df34dcf54","repo":"apache/flink","slug":"cannot-instantiate-tuple","errorCode":null,"errorMessage":"Cannot instantiate tuple.","messagePattern":"Cannot instantiate tuple\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/api/java/typeutils/runtime/TupleSerializer.java","lineNumber":78,"sourceCode":"        if (stateful) {\n            return new TupleSerializer<T>(tupleClass, duplicateFieldSerializers);\n        } else {\n            return this;\n        }\n    }\n\n    @Override\n    public T createInstance() {\n        try {\n            T t = instantiateRaw();\n\n            for (int i = 0; i < arity; i++) {\n                t.setField(fieldSerializers[i].createInstance(), i);\n            }\n\n            return t;\n        } catch (Exception e) {\n            throw new RuntimeException(\"Cannot instantiate tuple.\", e);\n        }\n    }\n\n    @Override\n    public T createInstance(Object[] fields) {\n\n        try {\n            T t = instantiateRaw();\n\n            for (int i = 0; i < arity; i++) {\n                t.setField(fields[i], i);\n            }\n\n            return t;\n        } catch (Exception e) {\n            throw new RuntimeException(\"Cannot instantiate tuple.\", e);\n        }\n    }","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/api/java/typeutils/runtime/TupleSerializer.java#L60-L96","documentation":"TupleSerializer.createInstance() reflectively instantiates the tuple class and creates default instances for every field via the field serializers. Any failure - tuple class not instantiable via the stored constructor, a field serializer's createInstance throwing - is wrapped in RuntimeException('Cannot instantiate tuple.'). It occurs while constructing empty/scratch tuple records for reuse in deserialization or operators.","triggerScenarios":"Creating a default tuple instance when the tupleClass stored in the serializer cannot be instantiated (no public no-arg constructor, abstract class, class not visible to the loader) or when one of the fieldSerializers fails to create a default field value. Often seen after deserializing a TupleSerializer built for a custom tuple subclass.","commonSituations":"Custom Tuple subclass with no no-arg constructor used as a type. Tuple class not public or loaded by a child classloader that loses visibility on the TaskManager. A custom field TypeSerializer whose createInstance depends on external state and throws.","solutions":["Ensure the tuple class is public, concrete, and has a public no-arg constructor (standard Tuple0..Tuple25 already do).","Check the nested cause: if a field serializer's createInstance threw, fix that serializer (return a sensible default instead of throwing).","If using a custom tuple subclass, make it static, public, and serializable, or switch to a built-in Tuple/Pojo type."],"exampleFix":"// before\npublic class MyTuple extends Tuple3<Long,String,Double> { // no no-arg ctor visible\n    MyTuple(Long l) { super(l, \"\", 0D); }\n}\n\n// after\npublic class MyTuple extends Tuple3<Long,String,Double> {\n    public MyTuple() {} // public no-arg ctor for reflective instantiation\n    public MyTuple(Long l) { super(l, \"\", 0D); }\n}","handlingStrategy":"validation","validationCode":"public static <T extends Tuple> void checkInstantiable(Class<T> tupleClass) {\n    int mods = tupleClass.getModifiers();\n    if (java.lang.reflect.Modifier.isAbstract(mods) || !java.lang.reflect.Modifier.isPublic(mods)) {\n        throw new IllegalStateException(tupleClass + \" must be public and concrete\");\n    }\n    try {\n        tupleClass.getDeclaredConstructor().newInstance();\n    } catch (ReflectiveOperationException e) {\n        throw new IllegalStateException(tupleClass + \" needs a public no-arg constructor\", e);\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    T t = serializer.createInstance();\n} catch (RuntimeException e) {\n    // cause is InstantiationException / field serializer failure; fix tuple ctor or field serializer\n}","preventionTips":["Custom tuple subclasses need a public no-arg constructor and public class modifier.","Field serializers' createInstance must never throw; return a default value.","Prefer built-in TupleN or Pojo types over custom tuple subclasses."],"tags":["tuple","instantiation","reflection","typeutils"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}