apache/beam · error · RuntimeException
Cannot infer schema from unparameterized collection.
Error message
Cannot infer schema from unparameterized collection.
What it means
fieldFromType infers an FieldType.iterable(elementType) for Collection-typed fields, but this requires the collection's element type parameter. If the Collection is declared raw (no generic parameter), the element type cannot be inferred and this RuntimeException is thrown.
Solutions
- Parameterize the collection field, e.g. List<String> or List<MyRowPojo>.
- Supply the field type explicitly in the schema rather than relying on inference.
- Use a TypeDescriptor that preserves the element type when calling inference APIs.
- For heterogeneous data, model as List<Row> with a defined row schema.
Example fix
// before private List items; // raw collection // after private List<String> items;
Defensive patterns
Strategy: type-guard
Validate before calling
for (java.lang.reflect.Field f : pojoClass.getDeclaredFields()) {
if (Collection.class.isAssignableFrom(f.getType())
&& !(f.getGenericType() instanceof java.lang.reflect.ParameterizedType)) {
throw new IllegalArgumentException("Raw Collection field: " + f.getName());
}
} Type guard
boolean hasParameterizedCollection(java.lang.reflect.Field f) {
return f.getGenericType() instanceof java.lang.reflect.ParameterizedType
&& Collection.class.isAssignableFrom(f.getType());
} Try / catch
try {
Schema s = Schema.of(pojoClass);
} catch (RuntimeException e) {
if (e.getMessage() != null && e.getMessage().contains("unparameterized collection")) {
throw new IllegalStateException("Parameterize Collection fields, e.g. List<String>", e);
}
throw e;
} Prevention
- Always parameterize List/Collection/Iterable fields
- Run compile with -Xlint:rawtypes in schema POJO packages
- Prefer List<Row> over raw heterogeneous collections
When it happens
Trigger: Schema inference encounters a field declared as a raw Collection/List (e.g. `private List items;` without `<T>`), reached from fieldType/fieldFromType.
Common situations: Pre-generics or sloppily typed POJOs, fields typed as Collection/List/Iterable without a type argument, or descriptors built from raw Classes losing parameterization.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- Cannot infer schema from unparameterized map.
- Arrow schema conversion does not support Beam type
- Cannot call getFromRowFunction when there is no schema
- Cannot call getSchema when there is no schema
- Cannot call getToRowFunction when there is no schema
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/ce14d41ba3b8e26a.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/utils/StaticSchemaInference.java:216
return FieldType.BYTES;
} else if (type.isSubtypeOf(TypeDescriptor.of(Iterable.class))) {
TypeDescriptor<Iterable<?>> iterable = type.getSupertype(Iterable.class);
if (iterable.getType() instanceof ParameterizedType) {
ParameterizedType ptype = (ParameterizedType) iterable.getType();
java.lang.reflect.Type[] params = ptype.getActualTypeArguments();
checkArgument(params.length == 1);
// TODO: should this be AbstractCollection?
if (type.isSubtypeOf(TypeDescriptor.of(Collection.class))) {
return FieldType.array(
fieldFromType(
TypeDescriptor.of(params[0]), fieldValueTypeSupplier, alreadyVisitedSchemas));
} else {
return FieldType.iterable(
fieldFromType(
TypeDescriptor.of(params[0]), fieldValueTypeSupplier, alreadyVisitedSchemas));
}
} else {
throw new RuntimeException("Cannot infer schema from unparameterized collection.");
}
} else {
return FieldType.row(schemaFromClass(type, fieldValueTypeSupplier, alreadyVisitedSchemas));
}
}
}
View on GitHub (pinned to 12126d8942)