Skip to content

Commit

Permalink
add null check to JobInfo.fromPb(Job) and .toPb() (#3770)
Browse files Browse the repository at this point in the history
Fixes #3739.
  • Loading branch information
sombra-mykola-bakay authored and pongad committed Oct 5, 2018
1 parent 211bfad commit d197058
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,9 @@ static final class BuilderImpl extends Builder {
this.statistics = JobStatistics.fromPb(jobPb);
}
this.userEmail = jobPb.getUserEmail();
this.configuration = JobConfiguration.fromPb(jobPb.getConfiguration());
if (jobPb.getConfiguration() != null) {
this.configuration = JobConfiguration.fromPb(jobPb.getConfiguration());
}
}

@Override
Expand Down Expand Up @@ -375,7 +377,9 @@ Job toPb() {
if (statistics != null) {
jobPb.setStatistics(statistics.toPb());
}
jobPb.setConfiguration(configuration.toPb());
if(configuration != null){
jobPb.setConfiguration(configuration.toPb());
}
return jobPb;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,16 @@ public void testToAndFromPb() {
compareJob(expectedJob, Job.fromPb(serviceMockReturnsOptions, expectedJob.toPb()));
}

@Test
public void testToAndFromPbWithoutConfiguration() {
JobInfo jobInfo =
JobInfo.newBuilder(null)
.build();
initializeExpectedJob(4, jobInfo);
replay(bigquery);
compareJob(expectedJob, Job.fromPb(serviceMockReturnsOptions, expectedJob.toPb()));
}

private void compareJob(Job expected, Job value) {
assertEquals(expected, value);
compareJobInfo(expected, value);
Expand Down

0 comments on commit d197058

Please sign in to comment.