{"record":{"id":"7da8b3e6013dca1d","repo":"apache/flink","slug":"cannot-create-hadoop-writabletypeinfo","errorCode":null,"errorMessage":"Cannot create Hadoop WritableTypeInfo.","messagePattern":"Cannot create Hadoop WritableTypeInfo\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"critical","filePath":"flink-core/src/main/java/org/apache/flink/api/java/typeutils/TypeExtractor.java","lineNumber":2477,"sourceCode":"                            Thread.currentThread().getContextClassLoader());\n        } catch (ClassNotFoundException e) {\n            throw new RuntimeException(\n                    \"Could not load the TypeInformation for the class '\"\n                            + HADOOP_WRITABLE_CLASS\n                            + \"'. You may be missing the 'flink-hadoop-compatibility' dependency.\");\n        }\n\n        try {\n            Constructor<?> constr = typeInfoClass.getConstructor(Class.class);\n\n            @SuppressWarnings(\"unchecked\")\n            TypeInformation<T> typeInfo = (TypeInformation<T>) constr.newInstance(clazz);\n            return typeInfo;\n        } catch (NoSuchMethodException | IllegalAccessException | InstantiationException e) {\n            throw new RuntimeException(\n                    \"Incompatible versions of the Hadoop Compatibility classes found.\");\n        } catch (InvocationTargetException e) {\n            throw new RuntimeException(\n                    \"Cannot create Hadoop WritableTypeInfo.\", e.getTargetException());\n        }\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","sourceCodeStart":2459,"sourceCodeEnd":2495,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/api/java/typeutils/TypeExtractor.java#L2459-L2495","documentation":"Thrown by TypeExtractor.createHadoopWritableTypeInfo when invoking the HadoopWritableTypeInfo constructor throws an InvocationTargetException — meaning the constructor itself was found and accessible but threw an exception during instantiation. This wraps the target exception from the constructor.","triggerScenarios":"Called during createHadoopWritableTypeInfo after constructor lookup succeeds, but constr.newInstance(clazz) throws InvocationTargetException. The HadoopWritableTypeInfo constructor threw an exception, possibly because the passed Writable class is invalid, has security restrictions, or failed internal validation.","commonSituations":"Passing a class to createHadoopWritableTypeInfo that does not properly implement Hadoop's Writable interface. Security manager restrictions preventing instantiation. Constructor internal validation rejecting the class (e.g., missing no-arg constructor on the Writable type, or the class is abstract).","solutions":["Inspect the wrapped target exception (e.getCause() or e.getTargetException()) for the root cause.","Ensure the Writable class has a public no-arg constructor as required by Hadoop Writable contract.","Verify the class is a concrete class (not abstract or interface) implementing org.apache.hadoop.io.Writable.","Check for security manager or classloader restrictions that might block reflective instantiation."],"exampleFix":"// before\npublic class MyWritable implements Writable {\n    // missing no-arg constructor, has only MyWritable(String s)\n}\n\n// after\npublic class MyWritable implements Writable {\n    public MyWritable() {} // required no-arg constructor\n    public MyWritable(String s) { ... }\n    public void write(DataOutput out) { ... }\n    public void readFields(DataInput in) { ... }\n}","handlingStrategy":"try-catch","validationCode":"// Verify the Writable class has a no-arg constructor before type extraction\ntry {\n    myWritableClass.getConstructor();\n    // OK\n} catch (NoSuchMethodException e) {\n    // Writable class missing no-arg constructor; fix the class\n}","typeGuard":"static boolean hasValidWritableConstructor(Class<?> clazz) {\n    try {\n        clazz.getConstructor();\n        return true;\n    } catch (NoSuchMethodException e) {\n        return false;\n    }\n}","tryCatchPattern":"try {\n    TypeInformation<?> ti = TypeExtractor.createHadoopWritableTypeInfo(MyWritable.class);\n} catch (RuntimeException e) {\n    if (e.getCause() != null) {\n        // inspect e.getCause() for the constructor's target exception\n    }\n}","preventionTips":["Ensure Writable classes have a public no-arg constructor.","Make Writable classes concrete (not abstract).","Check for security manager restrictions on reflective instantiation."],"tags":["hadoop","writable","reflection","instantiation"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}