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

  1. Declare the constructor parameter as List<ConcreteType> so the generic type is a ParameterizedType.
  2. Ensure getParameterValues passes genericTypes[i] from getGenericParameterTypes rather than null.
  3. Add a guard that resolves the element type from the schema field type when the generic type is not parameterized.
  4. 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

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


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/71835b6a2e68e1e4. Report an issue: GitHub.