{"record":{"id":"5821f1e0f8d28a8e","repo":"apache/flink","slug":"the-nothing-type-cannot-have-a-serializer","errorCode":null,"errorMessage":"The Nothing type cannot have a serializer.","messagePattern":"The Nothing type cannot have a serializer\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/api/common/typeinfo/NothingTypeInfo.java","lineNumber":72,"sourceCode":"        return 1;\n    }\n\n    @Override\n    @PublicEvolving\n    public Class<Nothing> getTypeClass() {\n        return Nothing.class;\n    }\n\n    @Override\n    @PublicEvolving\n    public boolean isKeyType() {\n        return false;\n    }\n\n    @Override\n    @PublicEvolving\n    public TypeSerializer<Nothing> createSerializer(SerializerConfig serializerConfig) {\n        throw new RuntimeException(\"The Nothing type cannot have a serializer.\");\n    }\n\n    @Override\n    public String toString() {\n        return getClass().getSimpleName();\n    }\n\n    @Override\n    public boolean equals(Object obj) {\n        if (obj instanceof NothingTypeInfo) {\n            NothingTypeInfo nothingTypeInfo = (NothingTypeInfo) obj;\n\n            return nothingTypeInfo.canEqual(this);\n        } else {\n            return false;\n        }\n    }\n","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/api/common/typeinfo/NothingTypeInfo.java#L54-L90","documentation":"NothingTypeInfo is the TypeInformation for the Nothing placeholder type, which represents an unreachable/empty type (e.g., a source that emits no elements, or a dead branch). Because Nothing has no instances, it has no serializer; createSerializer always throws RuntimeException. This is a sentinel: serializing Nothing is a programming error.","triggerScenarios":"Calling createSerializer on a NothingTypeInfo instance; a pipeline branch that resolves to Nothing (e.g., DataStreamSource with out-type Nothing) and downstream code that requests a serializer for it; TypeExtractor falling back to Nothing and then a serializer being requested.","commonSituations":"Building operator chains where one input branch has no real type; using APIs that force serializer creation on a stream whose TypeInformation is Nothing; test fixtures that accidentally wire a Nothing-typed source into a sink or state.","solutions":["Replace the Nothing-typed source/operator with one that emits a concrete type (e.g., define the source's returned TypeInformation explicitly).","Audit the pipeline for branches where TypeExtractor could not infer a type and defaulted to Nothing; supply an explicit TypeInformation/Returns hint on the source.","Never call createSerializer on a type you have not confirmed is real; guard with a check that typeInfo != NothingTypeInfo before requesting a serializer."],"exampleFix":"// before\nDataStream<Nothing> src = env.fromSource(noTypeSource, watermark, \"s\");\nsrc.getTransformation().getOutputType().createSerializer(cfg); // throws\n\n// after\nDataStream<Event> src = env.fromSource(\n    typedSource, watermark, \"s\", TypeInformation.of(Event.class));","handlingStrategy":"validation","validationCode":"TypeInformation<?> ti = source.getProducedType();\nif (ti instanceof NothingTypeInfo) {\n    throw new IllegalStateException(\n        \"Source type is Nothing; supply a concrete TypeInformation\");\n}","typeGuard":"static boolean isRealType(TypeInformation<?> ti) {\n    return !(ti instanceof NothingTypeInfo);\n}","tryCatchPattern":"try {\n    return ti.createSerializer(cfg);\n} catch (RuntimeException e) {\n    if (ti instanceof NothingTypeInfo) {\n        throw new IllegalStateException(\n            \"Cannot serialize Nothing; fix the source's output type\", e);\n    }\n    throw e;\n}","preventionTips":["Always specify a concrete TypeInformation/Returns on sources and operators; never let the pipeline default to Nothing.","Audit pipeline branches for unresolved types before requesting serializers.","Guard with `!(ti instanceof NothingTypeInfo)` in generic serializer-building code."],"tags":["type-information","nothing-type","sentinel","serializer"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}