Skip to content

fix: avoid NullPointerException in BigQuery.create() when the duplicated job cannot be re-fetched - #14026

Open
laughingman7743 wants to merge 1 commit into
googleapis:mainfrom
laughingman7743:fix-bigquery-create-duplicate-id-npe
Open

fix: avoid NullPointerException in BigQuery.create() when the duplicated job cannot be re-fetched#14026
laughingman7743 wants to merge 1 commit into
googleapis:mainfrom
laughingman7743:fix-bigquery-create-duplicate-id-npe

Conversation

@laughingman7743

Copy link
Copy Markdown

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Fixes #14025 ☕️

BigQuery.create(JobInfo)'s duplicate-job-id handler dereferences the getJob(...) re-fetch
unconditionally, but getJob returns null when the job cannot be seen — most commonly a job
outside the US multi-region looked up through a JobId that carries no location (the jobs.get
of a location-less JobId resolves against the US multi-region only). googleapis/java-bigquery#3035
narrowed the re-fetch to fields(STATISTICS) but did not guard the null return, and its test
covers the found-job path only, so googleapis/java-bigquery#3034's NPE still reproduces.

This guards the re-fetch and falls through to the original Already Exists exception, exactly as
the random-id branch a few lines below already does with its if (job == null) check. Verified
against BigQuery (a us-central1 dataset): the NullPointerException becomes the original
BigQueryException: Already Exists: Job <project>:<location>.<id>, whose message names the job's
actual location. The added test mirrors testCreateJobTryGetNotRandom with the re-fetch answering
not-found, and fails with the NPE when run without the fix.

…ted job cannot be re-fetched

The duplicate-job-id handler dereferences the getJob(...) re-fetch
unconditionally, but getJob returns null when the job cannot be seen -
most commonly a job outside the US multi-region looked up through a
JobId that carries no location. Guard it and fall through to the
original Already Exists exception, as the random-id branch below
already does.

Fixes googleapis#14025
@laughingman7743
laughingman7743 requested review from a team as code owners August 10, 2026 13:00

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a null check for the retrieved Job object in BigQueryImpl.java to prevent a potential NullPointerException when accessing its statistics. It also adds a corresponding unit test, testCreateJobTryGetNotRandomJobNotFound, in BigQueryImplTest.java to cover the scenario where the job is not found. There are no review comments, so no additional feedback is provided.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BigQuery: create() throws NullPointerException on a duplicate job id outside the US multi-region (java-bigquery#3034 not fixed by #3035)

1 participant