Skip to content
This repository was archived by the owner on Feb 24, 2026. It is now read-only.
This repository was archived by the owner on Feb 24, 2026. It is now read-only.

NullPointerException in JsonStreamWriter.Builder::build caused by unspecified field mode #1419

@C0urante

Description

@C0urante

Steps to reproduce

Create a TableFieldSchema without specifying the Mode for the field's schema, then create a TableSchema containing that field, then create a JsonStreamWriter with that schema.

Code example

BigQueryWriteClient client = createClient();
String table = String.format("projects/%s/datasets/%s/tables/%s", project(), dataset(), table());
TableFieldSchema fieldSchema = TableFieldSchema.newBuilder()
    .setName("f1")
    .setType(TableFieldSchema.Type.STRING)
    // If the line below is uncommented, no NPE is thrown
    // .setMode(TableFieldSchema.Mode.NULLABLE)
    .build();

TableSchema schema = TableSchema.newBuilder()
    .addFields(fieldSchema)
    .build();

JsonStreamWriter.newBuilder(table, schema, client).build();

Stack trace

java.lang.NullPointerException
	at com.google.protobuf.DescriptorProtos$FieldDescriptorProto$Builder.setLabel(DescriptorProtos.java:13430)
	at com.google.cloud.bigquery.storage.v1.BQTableSchemaToProtoDescriptor.convertBQTableFieldToProtoField(BQTableSchemaToProtoDescriptor.java:150)
	at com.google.cloud.bigquery.storage.v1.BQTableSchemaToProtoDescriptor.convertBQTableSchemaToProtoDescriptorImpl(BQTableSchemaToProtoDescriptor.java:113)
	at com.google.cloud.bigquery.storage.v1.BQTableSchemaToProtoDescriptor.convertBQTableSchemaToProtoDescriptor(BQTableSchemaToProtoDescriptor.java:72)
	at com.google.cloud.bigquery.storage.v1.JsonStreamWriter.<init>(JsonStreamWriter.java:62)
	at com.google.cloud.bigquery.storage.v1.JsonStreamWriter.<init>(JsonStreamWriter.java:39)
	at com.google.cloud.bigquery.storage.v1.JsonStreamWriter$Builder.build(JsonStreamWriter.java:333)

Any additional information below

Caused by a lookup of the BQTableSchemaModeMap map here with a key of TableFieldSchema.Mode.MODE_UNSPECIFIED, which is not included in the map's declaration here.

As a fix, it seems reasonable to either establish a default mode for these fields (I think NULLABLE is mentioned as the default here but not sure if that directly translates to desired behavior for the DDL API here), or fail to build a TableFieldSchema when no mode has been specified (unsure if this is possible with the code generation mechanism used for class, though). But anything that doesn't lead to an NPE would be nice :)

Metadata

Metadata

Labels

api: bigquerystorageIssues related to the googleapis/java-bigquerystorage API.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions