{"record":{"id":"6b74d3322c1f1689","repo":"apache/beam","slug":"attempted-to-encode-null-for-non-nullable-field-this-schema","errorCode":null,"errorMessage":"Attempted to encode null for non-nullable field \\\"${this.schema.fields[i].name}\\\".","messagePattern":"Attempted to encode null for non-nullable field \\\\\"(.+?)\\\\\"\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/typescript/src/apache_beam/coders/row_coder.ts","lineNumber":411,"sourceCode":"          }\n          running |= (attr === null || attr === undefined ? 1 : 0) << i % 8;\n        });\n        nullFields.push(running);\n      }\n    }\n\n    writer.bytes(new Uint8Array(nullFields));\n\n    // An encoding for each non-null field, concatenated together.\n    let positions = this.encodingPositionsAreTrivial\n      ? this.encodingPositions\n      : this.encodingPositionsArgsSorted;\n\n    positions.forEach((i) => {\n      let attr = attrs[i];\n      if (attr === null || attr === undefined) {\n        if (!this.fieldNullable[i]) {\n          throw new Error(\n            `Attempted to encode null for non-nullable field \\\"${this.schema.fields[i].name}\\\".`,\n          );\n        }\n      } else {\n        this.components[i].encode(attr, writer, Context.needsDelimiters);\n      }\n    });\n  }\n\n  decode(reader: Reader, context: Context): any {\n    let nFields = reader.int32();\n\n    // Addressing Null values\n    let nulls: any[],\n      hasNulls = false,\n      nullMaskBytes = reader.int32(),\n      nullMask = reader.buf.slice(reader.pos, reader.pos + nullMaskBytes);\n","sourceCodeStart":393,"sourceCodeEnd":429,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/typescript/src/apache_beam/coders/row_coder.ts#L393-L429","documentation":"During encode, the row value supplied for the named field was null or undefined while the schema declares that field non-nullable, and the null-bitmask machinery refuses to encode it. The faulty inputs are the element being encoded and the specific field named in the message.","triggerScenarios":"Thrown at sdks/typescript/src/apache_beam/coders/row_coder.ts:411 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Mark the field nullable in the schema (Field with nullable=true) if null is a legitimate value.","Fix the upstream DoFn so it never emits null/undefined for the named non-nullable field.","If null means 'absent', restructure the row to omit the field or use a sentinel value consistent with the schema."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}