{"record":{"id":"9e0de3ca447f8aac","repo":"apache/flink","slug":"org-apache-hadoop-io-writable-type-expected","errorCode":null,"errorMessage":"org.apache.hadoop.io.Writable type expected.","messagePattern":"org\\.apache\\.hadoop\\.io\\.Writable type expected\\.","errorType":"validation","errorClass":"InvalidTypesException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/api/java/typeutils/TypeExtractor.java","lineNumber":2497,"sourceCode":"        }\n    }\n\n    // visible for testing\n    static void validateIfWritable(TypeInformation<?> typeInfo, Type type) {\n        try {\n            // try to load the writable type info\n\n            Class<?> writableTypeInfoClass =\n                    Class.forName(\n                            HADOOP_WRITABLE_TYPEINFO_CLASS,\n                            false,\n                            typeInfo.getClass().getClassLoader());\n\n            if (writableTypeInfoClass.isAssignableFrom(typeInfo.getClass())) {\n                // this is actually a writable type info\n                // check if the type is a writable\n                if (!(type instanceof Class && isHadoopWritable((Class<?>) type))) {\n                    throw new InvalidTypesException(HADOOP_WRITABLE_CLASS + \" type expected.\");\n                }\n\n                // check writable type contents\n                Class<?> clazz = (Class<?>) type;\n                if (typeInfo.getTypeClass() != clazz) {\n                    throw new InvalidTypesException(\n                            \"Writable type '\"\n                                    + typeInfo.getTypeClass().getCanonicalName()\n                                    + \"' expected but was '\"\n                                    + clazz.getCanonicalName()\n                                    + \"'.\");\n                }\n            }\n        } catch (ClassNotFoundException e) {\n            // class not present at all, so cannot be that type info\n            // ignore\n        }\n    }","sourceCodeStart":2479,"sourceCodeEnd":2515,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/api/java/typeutils/TypeExtractor.java#L2479-L2515","documentation":"Thrown by TypeExtractor.validateIfWritable when a WritableTypeInfo is expected (the writable type info class is assignable from the given typeInfo) but the reflected type is not a Class that implements org.apache.hadoop.io.Writable. This means a Hadoop Writable type was declared but the actual extracted type is not a Writable.","triggerScenarios":"Called during validateIfWritable when writableTypeInfoClass.isAssignableFrom(typeInfo.getClass()) is true (meaning we have a WritableTypeInfo expectation) but the type is not a Class instance or isHadoopWritable((Class<?>) type) returns false. Occurs when a function declares a Hadoop Writable return/output type but the actual generic type resolves to a non-Writable class.","commonSituations":"Declaring a UDF output as a Hadoop Writable (e.g., Text) but actually using a String or POJO. Generic function signatures where the type parameter erases to a non-Writable class. Missing flink-hadoop-compatibility at validation time but the type info was constructed with it present (cross-module or classloader boundary).","solutions":["Ensure the UDF signature uses the actual Hadoop Writable subclass (e.g., org.apache.hadoop.io.Text, not String).","Provide explicit TypeInformation matching the actual type via .returns().","If the type is genuinely not a Writable, do not use a WritableTypeInfo; use the appropriate TypeInformation instead.","Add the flink-hadoop-compatibility dependency and ensure the Writable class is on the classpath."],"exampleFix":"// before\npublic String map(MyRecord r) { return r.getText(); }\n.returns(WritableTypeInfo.of(Text.class)) // mismatch\n\n// after\npublic Text map(MyRecord r) { return new Text(r.getText()); }\n.returns(WritableTypeInfo.of(Text.class))","handlingStrategy":"validation","validationCode":"// Check if the type is a Hadoop Writable before extraction\nif (type instanceof Class<?>) {\n    Class<?> clazz = (Class<?>) type;\n    // check implements org.apache.hadoop.io.Writable\n    boolean isWritable = org.apache.hadoop.io.Writable.class.isAssignableFrom(clazz);\n    if (!isWritable) {\n        // provide correct TypeInformation\n    }\n}","typeGuard":"static boolean isHadoopWritableType(Type t) {\n    if (!(t instanceof Class<?>)) return false;\n    try {\n        Class<?> writable = Class.forName(\"org.apache.hadoop.io.Writable\");\n        return writable.isAssignableFrom((Class<?>) t);\n    } catch (ClassNotFoundException e) {\n        return false;\n    }\n}","tryCatchPattern":"try {\n    validateIfWritable(typeInfo, type);\n} catch (InvalidTypesException e) {\n    // provide correct non-Writable TypeInformation\n    ti = TypeInformation.of((Class<?>) type);\n}","preventionTips":["Use actual Hadoop Writable subclasses in UDF signatures.","Do not declare WritableTypeInfo for non-Writable types.","Provide explicit TypeInformation matching the actual type."],"tags":["hadoop","writable","type-mismatch","typeinfo"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}