apache/beam · error · RuntimeException
Internal error: unexpected kind of Type:
Error message
Internal error: unexpected kind of Type:
What it means
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.
Source
Thrown at sdks/java/core/src/main/java/org/apache/beam/sdk/coders/CoderRegistry.java:638
String.format(
"Cannot provide a coder for type variable %s"
+ " because the actual type is over specified by multiple"
+ " incompatible coders %s.",
type, coders),
ReasonCode.OVER_SPECIFIED);
}
} else if (type instanceof Class<?>) {
coder = getCoderFromFactories(typeDescriptor, Collections.emptyList());
} else if (type instanceof ParameterizedType) {
coder = getCoderFromParameterizedType((ParameterizedType) type, typeCoderBindings);
} else if (type instanceof TypeVariable) {
coder = getCoderFromFactories(typeDescriptor, Collections.emptyList());
} else if (type instanceof WildcardType) {
// No coder for an unknown generic type.
throw new CannotProvideCoderException(
String.format("Cannot provide a coder for wildcard type %s.", type), ReasonCode.UNKNOWN);
} else {
throw new RuntimeException("Internal error: unexpected kind of Type: " + type);
}
LOG.debug("Coder for {}: {}", typeDescriptor, coder);
@SuppressWarnings("unchecked")
Coder<T> result = (Coder<T>) coder;
return result;
}
/**
* Returns a {@link Coder} to use for values of the given parameterized type, in a context where
* the given types use the given {@link Coder Coders}.
*
* @throws CannotProvideCoderException if no coder can be provided
*/
private Coder<?> getCoderFromParameterizedType(
ParameterizedType type, SetMultimap<Type, Coder<?>> typeCoderBindings)
throws CannotProvideCoderException {
View on GitHub (pinned to 12126d8942)
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).
Example fix
// before TypeDescriptor<T> td = TypeDescriptor.of(myCustomTypeImpl); // after TypeDescriptor<T> td = TypeDescriptor.of(ConcreteClass.class);
Defensive patterns
Strategy: try-catch
Validate before calling
Type t = typeDescriptor.getType();
if (!(t instanceof Class || t instanceof ParameterizedType
|| t instanceof TypeVariable || t instanceof WildcardType)) {
throw new IllegalArgumentException("Nonstandard Type: " + t.getClass());
} Type guard
static boolean isStandardReflectType(Type t) {
return t instanceof Class || t instanceof ParameterizedType
|| t instanceof TypeVariable || t instanceof WildcardType;
} Try / catch
try {
coder = registry.getCoder(td);
} catch (RuntimeException e) {
if (e.getMessage().startsWith("Internal error: unexpected kind of Type")) {
// log td.getType().getClass() and fix Type construction
}
} Prevention
- Build TypeDescriptors only from standard JDK Types.
- Log Type.getClass() when constructing descriptors dynamically.
- Report Beam bugs if a standard Type still triggers this.
When it happens
Trigger: 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.
Common situations: Third-party reflection libraries returning exotic Type implementations; bug in code constructing TypeDescriptor objects; Beam internal invariant breakage after library upgrade.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- error when invoking Coder factory method
- cannot register Coder : does not have an accessible method n
- cannot register Coder : method named 'of' with arguments of
- cannot register Coder : method named 'of' with arguments of
- cannot register Coder : method named 'of' with arguments of
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/0f0364b3ed326b2d.
Report an issue: GitHub.