{"record":{"id":"d98724f9650f5032","repo":"apache/beam","slug":"fieldtypevalue-has-no-value-but-the-field-cannot-be-null","errorCode":null,"errorMessage":"FieldTypeValue has no value but the field cannot be null.","messagePattern":"FieldTypeValue has no value but the field cannot be null\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/SchemaTranslation.java","lineNumber":622,"sourceCode":"            .setLogicalTypeValue(logicalTypeToProto(FieldType.INT64, fieldType, value))\n            .build();\n      case DECIMAL:\n        return builder\n            .setLogicalTypeValue(logicalTypeToProto(FieldType.BYTES, fieldType, value))\n            .build();\n      case LOGICAL_TYPE:\n        return builder\n            .setLogicalTypeValue(logicalTypeToProto(fieldType.getLogicalType(), value))\n            .build();\n      default:\n        return builder.setAtomicValue(primitiveRowFieldToProto(fieldType, value)).build();\n    }\n  }\n\n  /** Returns if the given field is null and throws exception if it is and can't be. */\n  static boolean isNullFieldValueFromProto(FieldType fieldType, boolean hasNonNullValue) {\n    if (!hasNonNullValue && !fieldType.getNullable()) {\n      throw new RuntimeException(\"FieldTypeValue has no value but the field cannot be null.\");\n    }\n    return !hasNonNullValue;\n  }\n\n  static Object fieldValueFromProto(FieldType fieldType, SchemaApi.FieldValue value) {\n    switch (fieldType.getTypeName()) {\n      case ARRAY:\n        if (isNullFieldValueFromProto(fieldType, value.hasArrayValue())) {\n          return null;\n        }\n        return arrayValueFromProto(fieldType.getCollectionElementType(), value.getArrayValue());\n      case ITERABLE:\n        if (isNullFieldValueFromProto(fieldType, value.hasIterableValue())) {\n          return null;\n        }\n        return iterableValueFromProto(\n            fieldType.getCollectionElementType(), value.getIterableValue());\n      case MAP:","sourceCodeStart":604,"sourceCodeEnd":640,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/SchemaTranslation.java#L604-L640","documentation":"isNullFieldValueFromProto checks a decoded proto FieldValue: if the proto message has no value set (hasNonNullValue false) but the corresponding Beam schema FieldType is not nullable, it throws this RuntimeException. It protects the invariant that non-nullable schema fields must always have a value on the wire.","triggerScenarios":"fieldValueFromProto calls isNullFieldValueFromProto on a FieldValue proto where hasValue() is false/unset while the target FieldType.getNullable() is false — e.g. proto produced by a writer that allowed nulls, reader schema says non-nullable.","commonSituations":"Schema evolution: field was nullable when the data was written, later tightened to non-nullable before decoding; proto FieldValue constructed programmatically without setting a value; deserializing into a schema from a different (stricter) source.","solutions":["Make the field nullable in the reading schema to match the data.","Re-encode the data with values present for every non-nullable field.","Align the schema used for decoding with the schema captured at write time (store schema alongside data).","Filter/repair records missing values before decoding (e.g. provide defaults via a map step)."],"exampleFix":"// before\nSchema.Field field = Schema.Field.of(\"name\", FieldType.STRING);\n// after\nSchema.Field field = Schema.Field.of(\"name\", FieldType.STRING.withNullable(true));","handlingStrategy":"validation","validationCode":"if (!fieldType.getNullable()) { /* require every decoded FieldValue to have hasValue() true before decode */ }","typeGuard":null,"tryCatchPattern":"try { rowFromProto(proto, schema); } catch (RuntimeException e) { if (e.getMessage().contains(\"no value but the field cannot be null\")) { /* align schema nullability with data */ } else { throw e; } }","preventionTips":["Store the schema with the data and decode with the same schema","Avoid tightening nullability after data has been written","Set a value on every FieldValue proto you construct manually","Run schema-compat checks in schema evolution workflows"],"tags":["java","null","schema","deserialization"],"backgroundTag":"schema-validation-failed","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"}