{"record":{"id":"b424af7dae948f6c","repo":"apache/hadoop","slug":"the-type-of-instance-is-instance-getclass","errorCode":null,"errorMessage":"The type of instance is: \" + instance.getClass() + \", which is NOT registered.","messagePattern":"The type of instance is: \" \\+ instance\\.getClass\\(\\) \\+ \", which is NOT registered\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/GenericWritable.java","lineNumber":106,"sourceCode":"  private Configuration conf = null;\n  \n  /**\n   * Set the instance that is wrapped.\n   * \n   * @param obj input obj.\n   */\n  public void set(Writable obj) {\n    instance = obj;\n    Class<? extends Writable> instanceClazz = instance.getClass();\n    Class<? extends Writable>[] clazzes = getTypes();\n    for (int i = 0; i < clazzes.length; i++) {\n      Class<? extends Writable> clazz = clazzes[i];\n      if (clazz.equals(instanceClazz)) {\n        type = (byte) i;\n        return;\n      }\n    }\n    throw new RuntimeException(\"The type of instance is: \"\n                               + instance.getClass() + \", which is NOT registered.\");\n  }\n\n  /**\n   * Return the wrapped instance.\n   * @return the wrapped instance.\n   */\n  public Writable get() {\n    return instance;\n  }\n  \n  @Override\n  public String toString() {\n    return \"GW[\" + (instance != null ? (\"class=\" + instance.getClass().getName() +\n        \",value=\" + instance.toString()) : \"(null)\") + \"]\";\n  }\n\n  @Override","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/GenericWritable.java#L88-L124","documentation":"GenericWritable serializes one of a fixed set of Writable types, identified by an index into the array returned by the subclass's getTypes(). set(Writable) scans that array for the instance's exact class and throws RuntimeException when it is absent — there is no type byte that could encode an unregistered class, and readFields() on the other end would not know how to reconstruct it.","triggerScenarios":"myGeneric.set(new Text(\"x\")) when getTypes() returns only {IntWritable.class, LongWritable.class}; adding a new Writable subtype to the data model but forgetting to append it to getTypes(); passing a subclass (e.g. MyText extends Text) whose exact class differs from the registered one — matching is clazz.equals(instanceClazz), not instanceof.","commonSituations":"Evolving a polymorphic field (e.g. a value column that can hold several writable types) across job versions; wrapping user subclasses where equals-based matching misses because the class is a subtype of the registered class.","solutions":["Append the missing class to the subclass's getTypes() array (append at the end to keep existing indexes stable for old data).","Ensure the exact runtime class is registered — register the concrete subclass, not just its superclass.","Never reorder getTypes(); index positions are the wire format."],"exampleFix":"// before\nclass MyGeneric extends GenericWritable {\n  protected Class<? extends Writable>[] getTypes() {\n    return new Class[] { IntWritable.class };\n  }\n}\nmyGeneric.set(new Text(\"x\")); // throws\n\n// after\nclass MyGeneric extends GenericWritable {\n  protected Class<? extends Writable>[] getTypes() {\n    return new Class[] { IntWritable.class, Text.class }; // appended, order stable\n  }\n}","handlingStrategy":"validation","validationCode":"Class<? extends Writable> c = candidate.getClass();\nboolean registered = Arrays.asList(getTypes()).contains(c);\nif (!registered) {\n  throw new IllegalArgumentException(c.getName() + \" not in getTypes(); append it at the end\");\n}\ngw.set(candidate);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Register the exact concrete class; matching is equals-based, not instanceof.","Append new types to getTypes() — never reorder or remove — because indexes are the wire format."],"tags":["hadoop","serialization","writable","type-registration","generic-writable"],"backgroundTag":"unregistered-class-serialization","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}