{"record":{"id":"cfe473b4c4612f6c","repo":"apache/beam","slug":"expected-a-java-primitive-value-but-received","errorCode":null,"errorMessage":"Expected a Java primitive value but received ","messagePattern":"Expected a Java primitive value but received ","errorType":"exception","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/expansion-service/src/main/java/org/apache/beam/sdk/expansion/service/JavaClassLookupTransformProvider.java","lineNumber":338,"sourceCode":"        @Nullable Row parameterRow = constructorRow.getRow(i);\n        Schema schema = getParameterSchema(parameterClass);\n        if (schema == null) {\n          throw new RuntimeException(\"Could not determine a schema for type \" + parameterClass);\n        }\n        if (parameterRow != null && !parameterRow.getSchema().assignableTo(schema)) {\n          return false;\n        }\n      }\n    }\n    return true;\n  }\n\n  @SuppressWarnings(\"argument\")\n  private @Nullable Object getDecodedValueFromRow(\n      Class<?> type, Object valueFromRow, @Nullable Type genericType) {\n    if (isPrimitiveOrWrapperOrString(type)) {\n      if (!isPrimitiveOrWrapperOrString(valueFromRow.getClass())) {\n        throw new IllegalArgumentException(\n            \"Expected a Java primitive value but received \" + valueFromRow);\n      }\n      return valueFromRow;\n    } else if (type.isArray()) {\n      Class<?> arrayComponentClass = type.getComponentType();\n      return getDecodedArrayValueFromRow(arrayComponentClass, valueFromRow);\n    } else if (Collection.class.isAssignableFrom(type)) {\n      List<Object> originalList = (List) valueFromRow;\n      List<Object> decodedList = new ArrayList<>();\n      for (Object obj : originalList) {\n        if (genericType instanceof ParameterizedType) {\n          Class<?> elementType =\n              (Class<?>) ((ParameterizedType) genericType).getActualTypeArguments()[0];\n          decodedList.add(getDecodedValueFromRow(elementType, obj, null));\n        } else {\n          throw new RuntimeException(\"Could not determine the generic type of the list\");\n        }\n      }","sourceCodeStart":320,"sourceCodeEnd":356,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/expansion-service/src/main/java/org/apache/beam/sdk/expansion/service/JavaClassLookupTransformProvider.java#L320-L356","documentation":"JavaClassLookupTransformProvider decodes constructor arguments that arrive as Beam Rows back into Java objects. When the target constructor parameter is a primitive/wrapper/String, the decoder checks that the value supplied in the Row is also a primitive/wrapper/String. If the Row cell holds a different type (e.g. a Row or a List), it throws IllegalArgumentException.","triggerScenarios":"Calling the expansion service to construct a PTransform whose constructor takes a primitive/wrapper/String parameter, but the constructorSchema Row contains a non-primitive value (nested Row, List, or byte array) at that field position.","commonSituations":"Schema field typed as ROW or ARRAY in the payload while the Java constructor expects int/long/String; cross-language pipeline where the constructing SDK serializes a struct but the Java class expects a scalar; type drift after regenerating the constructor schema.","solutions":["Fix the constructor schema so the field type matches the Java parameter type (primitive/wrapper/String vs ROW/ARRAY).","Verify the parameter order/field mapping so primitive parameters line up with scalar Row fields.","If the value is genuinely structured, change the constructor parameter to a schema-registered class instead of a primitive.","Wrap getParameterValues/parameterValue in try-catch on IllegalArgumentException and fail the expansion request with a clear schema-mismatch message."],"exampleFix":"// before: Row field is a nested Row but constructor expects long\nRow.ofSchema(constructorSchema, Arrays.asList(Row.of(...), 42L))\n// after: supply a scalar matching the constructor parameter type\nRow.ofSchema(constructorSchema, Arrays.asList(\"name\", 42L))","handlingStrategy":"validation","validationCode":"boolean isScalar(Object v) { return v instanceof String || v instanceof Number || v instanceof Boolean || v instanceof Character; }\n// verify each constructorSchema field is scalar before calling the expansion service","typeGuard":"boolean matchesPrimitiveParam(Class<?> param, Object rowValue) { return (param.isPrimitive() || Number.class.isAssignableFrom(param) || param == String.class) && isScalar(rowValue); }","tryCatchPattern":null,"preventionTips":["Keep constructor schema field types aligned 1:1 with Java parameter types","Validate the payload Row against the constructor schema before sending","Avoid nesting Rows where constructors expect primitives","Add expansion-service integration tests for each constructor signature"],"tags":["java","row-decoding","schema-mismatch","type-mismatch"],"backgroundTag":"type-mismatch","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}