Skip to content

BigQuery Java Client throws NPE when a query takes more than 10 seconds with useReadAPI(false) #2508

@jonathanswenson

Description

@jonathanswenson

Thanks for stopping by to let us know something could be better!

Environment details

  1. Specify the API at the beginning of the title. For example, "BigQuery: ...").
    General, Core, and Other are also allowed as types: Bigquery Java Client
  2. OS type and version:
  3. Java version: 17 adoptium
  4. version(s): 2.19.2 and 2.20.0

Steps to reproduce

  1. set setUseReadAPI(false) on ConnectionSettings before building a connection
  2. run a query that takes more than 10 seconds using the com.google.cloud.bigquery.Connection query APIs.

Sample Code

Standard usage with query that takes longer than 10 seconds (falls out of the fast query path).

ConnectionSettings connectionSettings =
ConnectionSettings.newBuilder()
       .setUseReadAPI(false)
       .setRequestTimeout(10L)
       .setMaxResults(100L)
       .setUseQueryCache(true)
       .build();
Connection connection = bigquery.createConnection(connectionSettings);
String selectQuery = "<query that takes a little while and moves past the initial jobs.query timeout";
ListenableFuture<ExecuteSelectResponse> executeSelectFuture = connection.executeSelectAsync(selectQuery, ...);

Stack trace

java.lang.NullPointerException: Cannot invoke "java.lang.Long.longValue()" because "totalRows" is null
	at com.google.cloud.bigquery.ConnectionImpl.useReadAPI(ConnectionImpl.java:1220)
	at com.google.cloud.bigquery.ConnectionImpl.getSubsequentQueryResultsWithJob(ConnectionImpl.java:844)
	at com.google.cloud.bigquery.ConnectionImpl.queryRpc(ConnectionImpl.java:486)
	at com.google.cloud.bigquery.ConnectionImpl.getExecuteSelectResponse(ConnectionImpl.java:236)
	at com.google.cloud.bigquery.ConnectionImpl.executeSelect(ConnectionImpl.java:218)
	at com.google.cloud.bigquery.ConnectionImpl.lambda$getExecuteSelectFuture$0(ConnectionImpl.java:305)
	at com.google.common.util.concurrent.TrustedListenableFutureTask$TrustedFutureInterruptibleTask.runInterruptibly(TrustedListenableFutureTask.java:131)
	at com.google.common.util.concurrent.InterruptibleTask.run(InterruptibleTask.java:74)
	at com.google.common.util.concurrent.TrustedListenableFutureTask.run(TrustedListenableFutureTask.java:82)
	... 3 more

Any additional information below

Looks like the exception is being thrown here: https://github.com/googleapis/java-bigquery/blob/v2.21.0/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/ConnectionImpl.java#L1220

Moving that check inside the if statement below it (which I think should be safe because of the check at the beginning of the method for null AND readAPI = true) should fix it.

Following these steps guarantees the quickest resolution possible.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    api: bigqueryIssues related to the googleapis/java-bigquery API.priority: p3Desirable enhancement or 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