apache/beam · error · java.lang.RuntimeException
Could not determine the generic type of the list
Error message
Could not determine the generic type of the list
What it means
When decoding a java.util.List constructor parameter, the decoder needs the element type from the declared generic type of the parameter. If the generic type is not a ParameterizedType (e.g. raw List or unknown Type), the element type cannot be determined and it throws RuntimeException.
Source
Thrown at sdks/java/expansion-service/src/main/java/org/apache/beam/sdk/expansion/service/JavaClassLookupTransformProvider.java:354
if (isPrimitiveOrWrapperOrString(type)) {
if (!isPrimitiveOrWrapperOrString(valueFromRow.getClass())) {
throw new IllegalArgumentException(
"Expected a Java primitive value but received " + valueFromRow);
}
return valueFromRow;
} else if (type.isArray()) {
Class<?> arrayComponentClass = type.getComponentType();
return getDecodedArrayValueFromRow(arrayComponentClass, valueFromRow);
} else if (Collection.class.isAssignableFrom(type)) {
List<Object> originalList = (List) valueFromRow;
List<Object> decodedList = new ArrayList<>();
for (Object obj : originalList) {
if (genericType instanceof ParameterizedType) {
Class<?> elementType =
(Class<?>) ((ParameterizedType) genericType).getActualTypeArguments()[0];
decodedList.add(getDecodedValueFromRow(elementType, obj, null));
} else {
throw new RuntimeException("Could not determine the generic type of the list");
}
}
return decodedList;
} else if (valueFromRow instanceof Row) {
Row row = (Row) valueFromRow;
SerializableFunction<Row, ?> fromRowFunc;
try {
fromRowFunc = SCHEMA_REGISTRY.getFromRowFunction(type);
} catch (NoSuchSchemaException e) {
throw new IllegalArgumentException(
"Could not determine the row function for class " + type, e);
}
return fromRowFunc.apply(row);
}
throw new RuntimeException("Could not decode the value from Row " + valueFromRow);
}
@SuppressWarnings("argument")View on GitHub (pinned to 12126d8942)
Solutions
- Declare the constructor parameter as List<ConcreteType> so the generic type is a ParameterizedType.
- Ensure getParameterValues passes genericTypes[i] from getGenericParameterTypes rather than null.
- Add a guard that resolves the element type from the schema field type when the generic type is not parameterized.
- Catch RuntimeException in the expansion path and return a descriptive error to the requesting SDK.
Example fix
// before
public MyTransform(List rawList) {...}
// after
public MyTransform(java.util.List<String> items) {...} Defensive patterns
Strategy: type-guard
Validate before calling
Type t = genericTypes[i]; if (!(t instanceof ParameterizedType)) throw new IllegalArgumentException("List parameter " + i + " lacks generic element type"); Type guard
boolean hasElementType(Type t) { return t instanceof ParameterizedType && ((ParameterizedType) t).getActualTypeArguments().length == 1 && ((ParameterizedType) t).getActualTypeArguments()[0] instanceof Class; } Try / catch
try { decodeList(...); } catch (RuntimeException e) { throw new IllegalArgumentException("Declare List<ElementType> with generics retained", e); } Prevention
- Never use raw List types in constructor signatures
- Pass getGenericParameterTypes() results, not getClass() results
- Keep -parameters/generic signature info in builds
- Unit-test constructors containing generic collections
When it happens
Trigger: A constructor parameter is List<T> but genericTypes passed to getDecodedValueFromRow is null or a raw Class (not ParameterizedType) — e.g. generic type information was lost via erasure or the caller passed null for genericType.
Common situations: Constructors using raw List types; reflection over generic signatures where getGenericParameterTypes was not used; expansion payloads built by hand instead of by schema tooling.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- Unable to infer SQL type from type variable . This usually m
- Cannot infer coder for type parameter
- is not a ParameterizedType
- Cannot encode elements of type %s with coder %s: the generic
- Cannot provide a coder for wildcard type %s.
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/71835b6a2e68e1e4.
Report an issue: GitHub.