{"record":{"id":"ce14d41ba3b8e26a","repo":"apache/beam","slug":"cannot-infer-schema-from-unparameterized-collection","errorCode":null,"errorMessage":"Cannot infer schema from unparameterized collection.","messagePattern":"Cannot infer schema from unparameterized collection\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/utils/StaticSchemaInference.java","lineNumber":216,"sourceCode":"      return FieldType.BYTES;\n    } else if (type.isSubtypeOf(TypeDescriptor.of(Iterable.class))) {\n      TypeDescriptor<Iterable<?>> iterable = type.getSupertype(Iterable.class);\n      if (iterable.getType() instanceof ParameterizedType) {\n        ParameterizedType ptype = (ParameterizedType) iterable.getType();\n        java.lang.reflect.Type[] params = ptype.getActualTypeArguments();\n        checkArgument(params.length == 1);\n        // TODO: should this be AbstractCollection?\n        if (type.isSubtypeOf(TypeDescriptor.of(Collection.class))) {\n          return FieldType.array(\n              fieldFromType(\n                  TypeDescriptor.of(params[0]), fieldValueTypeSupplier, alreadyVisitedSchemas));\n        } else {\n          return FieldType.iterable(\n              fieldFromType(\n                  TypeDescriptor.of(params[0]), fieldValueTypeSupplier, alreadyVisitedSchemas));\n        }\n      } else {\n        throw new RuntimeException(\"Cannot infer schema from unparameterized collection.\");\n      }\n    } else {\n      return FieldType.row(schemaFromClass(type, fieldValueTypeSupplier, alreadyVisitedSchemas));\n    }\n  }\n}\n","sourceCodeStart":198,"sourceCodeEnd":223,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/utils/StaticSchemaInference.java#L198-L223","documentation":"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.","triggerScenarios":"Schema inference encounters a field declared as a raw Collection/List (e.g. `private List items;` without `<T>`), reached from fieldType/fieldFromType.","commonSituations":"Pre-generics or sloppily typed POJOs, fields typed as Collection/List/Iterable without a type argument, or descriptors built from raw Classes losing parameterization.","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."],"exampleFix":"// before\nprivate List items; // raw collection\n// after\nprivate List<String> items;","handlingStrategy":"type-guard","validationCode":"for (java.lang.reflect.Field f : pojoClass.getDeclaredFields()) {\n  if (Collection.class.isAssignableFrom(f.getType())\n      && !(f.getGenericType() instanceof java.lang.reflect.ParameterizedType)) {\n    throw new IllegalArgumentException(\"Raw Collection field: \" + f.getName());\n  }\n}","typeGuard":"boolean hasParameterizedCollection(java.lang.reflect.Field f) {\n  return f.getGenericType() instanceof java.lang.reflect.ParameterizedType\n      && Collection.class.isAssignableFrom(f.getType());\n}","tryCatchPattern":"try {\n  Schema s = Schema.of(pojoClass);\n} catch (RuntimeException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"unparameterized collection\")) {\n    throw new IllegalStateException(\"Parameterize Collection fields, e.g. List<String>\", e);\n  }\n  throw e;\n}","preventionTips":["Always parameterize List/Collection/Iterable fields","Run compile with -Xlint:rawtypes in schema POJO packages","Prefer List<Row> over raw heterogeneous collections"],"tags":["java","schema","generics","collection"],"backgroundTag":"missing-required-argument","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}