Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BigQuery: BigQuery.getTable(TableId) throws NullPointerException when TableId contains an empty table name. #6277

Closed
srgrr opened this issue Sep 16, 2019 · 0 comments · Fixed by #6284
Assignees
Labels
api: bigquery Issues related to the BigQuery API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@srgrr
Copy link

srgrr commented Sep 16, 2019

Environment details

  1. API: google-cloud-bigquery
  2. OS type and version: macOS 10.14.6
  3. Java version: 1.8.0_221
  4. google-cloud-java version(s): 1.91.0

More precisely, the only google-related dependency included in my pom.xml is the following:

    <dependency>
      <groupId>com.google.cloud</groupId>
      <artifactId>google-cloud-bigquery</artifactId>
      <version>1.91.0</version>
    </dependency>

Steps to reproduce

  1. Include this in your pom.xml:
    <dependency>
      <groupId>com.google.cloud</groupId>
      <artifactId>google-cloud-bigquery</artifactId>
      <version>1.91.0</version>
    </dependency>
  1. Adapt and run this code:
import com.google.auth.Credentials;
import com.google.auth.oauth2.ServiceAccountCredentials;
import com.google.cloud.bigquery.BigQuery;
import com.google.cloud.bigquery.BigQueryOptions;
import com.google.cloud.bigquery.Table;
import com.google.cloud.bigquery.TableId;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

public class Main {

  private static final String CREDENTIALS_PATH = "/Users/sergiorodriguez/key.json";
  private static final String PROJECT_ID = "streamsets-engineering";
  private static final String DATASET_NAME = "sergio_dataset";
  // Will throw NullPointerException if empty, and specific error if not empty
  private static final String TABLE_NAME = "";

  private Credentials getCredentials(String path) throws IOException {
    File credentialsFile = new File(path);
    return ServiceAccountCredentials.fromStream(new FileInputStream(credentialsFile));
  }

  private Main() throws IOException {
    Credentials credentials = getCredentials(CREDENTIALS_PATH);
    BigQueryOptions options = BigQueryOptions.newBuilder()
                                             .setCredentials(credentials)
                                             .setProjectId(PROJECT_ID)
                                             .build();
    BigQuery bigQuery = options.getService();
    TableId tableId = TableId.of(DATASET_NAME, TABLE_NAME);
    Table table = bigQuery.getTable(tableId);
    System.out.println(table);
  }

  public static void main(String[] args) throws IOException {
    new Main();
  }
}

Stack trace

Exception in thread "main" java.lang.NullPointerException
	at com.google.cloud.bigquery.TableId.fromPb(TableId.java:108)
	at com.google.cloud.bigquery.TableInfo$BuilderImpl.<init>(TableInfo.java:174)
	at com.google.cloud.bigquery.Table.fromPb(Table.java:624)
	at com.google.cloud.bigquery.BigQueryImpl.getTable(BigQueryImpl.java:677)
	at es.sergiorgs.Main.<init>(Main.java:51)
	at es.sergiorgs.Main.main(Main.java:56)

Any additional information below

If TABLE_NAME is not empty then it works as expected (i.e: specific, expected responses for invalid table names, returning null when table does not exist and so on).

It feels very similar to #3982 . However, this issue appears as fixed.

@pmakani pmakani added api: bigquery Issues related to the BigQuery API. type: question Request for information or clarification. Not an issue. labels Sep 16, 2019
@pmakani pmakani self-assigned this Sep 16, 2019
@pmakani pmakani added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. priority: p2 Moderately-important priority. Fix may not be included in next release. and removed type: question Request for information or clarification. Not an issue. labels Sep 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: bigquery Issues related to the BigQuery API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
2 participants