{"record":{"id":"0f0364b3ed326b2d","repo":"apache/beam","slug":"internal-error-unexpected-kind-of-type","errorCode":null,"errorMessage":"Internal error: unexpected kind of Type: ","messagePattern":"Internal error: unexpected kind of Type: ","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/coders/CoderRegistry.java","lineNumber":638,"sourceCode":"            String.format(\n                \"Cannot provide a coder for type variable %s\"\n                    + \" because the actual type is over specified by multiple\"\n                    + \" incompatible coders %s.\",\n                type, coders),\n            ReasonCode.OVER_SPECIFIED);\n      }\n    } else if (type instanceof Class<?>) {\n      coder = getCoderFromFactories(typeDescriptor, Collections.emptyList());\n    } else if (type instanceof ParameterizedType) {\n      coder = getCoderFromParameterizedType((ParameterizedType) type, typeCoderBindings);\n    } else if (type instanceof TypeVariable) {\n      coder = getCoderFromFactories(typeDescriptor, Collections.emptyList());\n    } else if (type instanceof WildcardType) {\n      // No coder for an unknown generic type.\n      throw new CannotProvideCoderException(\n          String.format(\"Cannot provide a coder for wildcard type %s.\", type), ReasonCode.UNKNOWN);\n    } else {\n      throw new RuntimeException(\"Internal error: unexpected kind of Type: \" + type);\n    }\n\n    LOG.debug(\"Coder for {}: {}\", typeDescriptor, coder);\n    @SuppressWarnings(\"unchecked\")\n    Coder<T> result = (Coder<T>) coder;\n    return result;\n  }\n\n  /**\n   * Returns a {@link Coder} to use for values of the given parameterized type, in a context where\n   * the given types use the given {@link Coder Coders}.\n   *\n   * @throws CannotProvideCoderException if no coder can be provided\n   */\n  private Coder<?> getCoderFromParameterizedType(\n      ParameterizedType type, SetMultimap<Type, Coder<?>> typeCoderBindings)\n      throws CannotProvideCoderException {\n","sourceCodeStart":620,"sourceCodeEnd":656,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/coders/CoderRegistry.java#L620-L656","documentation":"getCoderFromTypeDescriptor dispatches on the kind of java.lang.reflect.Type it received (Class, ParameterizedType, TypeVariable, WildcardType). If the Type is none of these known kinds, an internal invariant is violated and the registry throws a bare RuntimeException labelled as an internal error. This should be unreachable in normal use and usually signals a nonstandard Type implementation.","triggerScenarios":"Passing a Type object that is not Class, ParameterizedType, TypeVariable, or WildcardType — typically a custom/unusual Type implementation or a corrupt descriptor produced by other reflection code — into getCoder/getDefaultCoders.","commonSituations":"Third-party reflection libraries returning exotic Type implementations; bug in code constructing TypeDescriptor objects; Beam internal invariant breakage after library upgrade.","solutions":["Inspect and log the offending Type object's class to identify where the nonstandard Type comes from.","Replace custom Type implementations with standard JDK Class/ParameterizedType instances when building TypeDescriptors.","Update/patch Apache Beam if the Type was produced by Beam itself (report the bug)."],"exampleFix":"// before\nTypeDescriptor<T> td = TypeDescriptor.of(myCustomTypeImpl);\n// after\nTypeDescriptor<T> td = TypeDescriptor.of(ConcreteClass.class);","handlingStrategy":"try-catch","validationCode":"Type t = typeDescriptor.getType();\nif (!(t instanceof Class || t instanceof ParameterizedType\n    || t instanceof TypeVariable || t instanceof WildcardType)) {\n  throw new IllegalArgumentException(\"Nonstandard Type: \" + t.getClass());\n}","typeGuard":"static boolean isStandardReflectType(Type t) {\n  return t instanceof Class || t instanceof ParameterizedType\n      || t instanceof TypeVariable || t instanceof WildcardType;\n}","tryCatchPattern":"try {\n  coder = registry.getCoder(td);\n} catch (RuntimeException e) {\n  if (e.getMessage().startsWith(\"Internal error: unexpected kind of Type\")) {\n    // log td.getType().getClass() and fix Type construction\n  }\n}","preventionTips":["Build TypeDescriptors only from standard JDK Types.","Log Type.getClass() when constructing descriptors dynamically.","Report Beam bugs if a standard Type still triggers this."],"tags":["java","apache-beam","reflection","internal-error"],"backgroundTag":"internal-invariant-violation","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T21:17:11.552Z"}