{"record":{"id":"1264abcea28a7bb1","repo":"apache/beam","slug":"tableref-is-missing-projectid-s","errorCode":null,"errorMessage":"tableRef is missing projectId: %s","messagePattern":"tableRef is missing projectId: (.+?)","errorType":"validation","errorClass":"NullPointerException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/testing/FakeDatasetService.java","lineNumber":272,"sourceCode":"  static AtomicInteger insertCount;\n\n  public static void setUp() {\n    synchronized (FakeDatasetService.class) {\n      tables = HashBasedTable.create();\n      insertCount = new AtomicInteger(0);\n      writeStreams = Maps.newHashMap();\n      FakeJobService.setUp();\n    }\n  }\n\n  public void setShouldFailRow(Function<TableRow, Boolean> shouldFailRow) {\n    this.shouldFailRow = shouldFailRow;\n  }\n\n  @Override\n  public Table getTable(TableReference tableRef) throws InterruptedException, IOException {\n    if (tableRef.getProjectId() == null) {\n      throw new NullPointerException(String.format(\"tableRef is missing projectId: %s\", tableRef));\n    }\n    return getTable(tableRef, null);\n  }\n\n  @Override\n  public Table getTable(TableReference tableRef, @Nullable List<String> selectedFields)\n      throws InterruptedException, IOException {\n    return getTable(tableRef, selectedFields, null);\n  }\n\n  @Override\n  public Table getTable(\n      TableReference tableRef,\n      @Nullable List<String> selectedFields,\n      @Nullable TableMetadataView view)\n      throws InterruptedException, IOException {\n    return getTableImpl(tableRef, selectedFields, view);\n  }","sourceCodeStart":254,"sourceCodeEnd":290,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/testing/FakeDatasetService.java#L254-L290","documentation":"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.","triggerScenarios":"Calling getTable() with a TableReference built without setProjectId(); numBytes() or the testRemoveTemporaryTables path encountering such a reference.","commonSituations":"Constructing a TableReference with only dataset and table id; deserializing references from config where the project field is absent or empty.","solutions":["Set projectId on the TableReference before calling getTable (tableRef.setProjectId(\"my-project\"))","If the project is implicit, take it from job options (e.g. BigQueryOptions/credentials project) and apply it before the call","Validate the reference in test setup so the failure surfaces early with a clear assertion"],"exampleFix":"// before\nTableReference ref = TableReference.newBuilder().setDatasetId(\"ds\").setTableId(\"t\").build();\nTable t = service.getTable(ref); // NPE\n// after\nref.setProjectId(\"my-project\");\nTable t = service.getTable(ref);","handlingStrategy":"validation","validationCode":"if (tableRef == null || tableRef.getProjectId() == null) {\n  throw new IllegalArgumentException(\"TableReference requires a projectId\");\n}","typeGuard":"boolean hasProject(TableReference ref) {\n  return ref != null && ref.getProjectId() != null && !ref.getProjectId().isEmpty();\n}","tryCatchPattern":"try {\n  Table t = service.getTable(ref);\n} catch (NullPointerException e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"tableRef is missing projectId\")) {\n    throw new IllegalStateException(\"Set projectId on TableReference\", e);\n  }\n  throw e;\n}","preventionTips":["Always build TableReference via a helper that requires projectId","Default the project from BigQueryOptions.getProjectId() in setup","Assert reference completeness in test @Before hooks"],"tags":["bigquery","null-argument","java","test-fake"],"backgroundTag":"missing-required-argument","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"}