fix: avoid NullPointerException in BigQuery.create() when the duplicated job cannot be re-fetched - #14026
Open
laughingman7743 wants to merge 1 commit into
Conversation
…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
Contributor
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
Fixes #14025 ☕️
BigQuery.create(JobInfo)'s duplicate-job-id handler dereferences thegetJob(...)re-fetchunconditionally, but
getJobreturns null when the job cannot be seen — most commonly a joboutside the US multi-region looked up through a
JobIdthat carries no location (thejobs.getof a location-less
JobIdresolves against the US multi-region only). googleapis/java-bigquery#3035narrowed the re-fetch to
fields(STATISTICS)but did not guard the null return, and its testcovers 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 Existsexception, exactly asthe random-id branch a few lines below already does with its
if (job == null)check. Verifiedagainst BigQuery (a
us-central1dataset): theNullPointerExceptionbecomes the originalBigQueryException: Already Exists: Job <project>:<location>.<id>, whose message names the job'sactual location. The added test mirrors
testCreateJobTryGetNotRandomwith the re-fetch answeringnot-found, and fails with the NPE when run without the fix.