apache/beam · error · NullPointerException

tableRef is missing projectId

Error message

tableRef is missing projectId: %s

What it means

FakeDatasetService.getTable(TableReference) throws a NullPointerException when the tableRef has no projectId set. This fake mirrors BigQuery's requirement that a TableReference always identify a project. It is thrown eagerly so tests fail fast on malformed references.

Solutions

  1. Set projectId on the TableReference before calling getTable (tableRef.setProjectId("my-project"))
  2. If the project is implicit, take it from job options (e.g. BigQueryOptions/credentials project) and apply it before the call
  3. Validate the reference in test setup so the failure surfaces early with a clear assertion

Example fix

// before
TableReference ref = TableReference.newBuilder().setDatasetId("ds").setTableId("t").build();
Table t = service.getTable(ref); // NPE
// after
ref.setProjectId("my-project");
Table t = service.getTable(ref);
Defensive patterns

Strategy: validation

Validate before calling

if (tableRef == null || tableRef.getProjectId() == null) {
  throw new IllegalArgumentException("TableReference requires a projectId");
}

Type guard

boolean hasProject(TableReference ref) {
  return ref != null && ref.getProjectId() != null && !ref.getProjectId().isEmpty();
}

Try / catch

try {
  Table t = service.getTable(ref);
} catch (NullPointerException e) {
  if (e.getMessage() != null && e.getMessage().startsWith("tableRef is missing projectId")) {
    throw new IllegalStateException("Set projectId on TableReference", e);
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling getTable() with a TableReference built without setProjectId(); numBytes() or the testRemoveTemporaryTables path encountering such a reference.

Common situations: Constructing a TableReference with only dataset and table id; deserializing references from config where the project field is absent or empty.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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

Appendix: source

Thrown at sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/testing/FakeDatasetService.java:272

  static AtomicInteger insertCount;

  public static void setUp() {
    synchronized (FakeDatasetService.class) {
      tables = HashBasedTable.create();
      insertCount = new AtomicInteger(0);
      writeStreams = Maps.newHashMap();
      FakeJobService.setUp();
    }
  }

  public void setShouldFailRow(Function<TableRow, Boolean> shouldFailRow) {
    this.shouldFailRow = shouldFailRow;
  }

  @Override
  public Table getTable(TableReference tableRef) throws InterruptedException, IOException {
    if (tableRef.getProjectId() == null) {
      throw new NullPointerException(String.format("tableRef is missing projectId: %s", tableRef));
    }
    return getTable(tableRef, null);
  }

  @Override
  public Table getTable(TableReference tableRef, @Nullable List<String> selectedFields)
      throws InterruptedException, IOException {
    return getTable(tableRef, selectedFields, null);
  }

  @Override
  public Table getTable(
      TableReference tableRef,
      @Nullable List<String> selectedFields,
      @Nullable TableMetadataView view)
      throws InterruptedException, IOException {
    return getTableImpl(tableRef, selectedFields, view);
  }

View on GitHub (pinned to 12126d8942)