Skip to content

Commit 99f0a87

Browse files
Fixes googleapis#3739. Null check added to JobInfo fromPb(Job jobPb) and toPb() methods
1 parent 7f74c5a commit 99f0a87

File tree

2 files changed

+16
-2
lines changed
  • google-cloud-clients/google-cloud-bigquery/src

2 files changed

+16
-2
lines changed

google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/JobInfo.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,9 @@ static final class BuilderImpl extends Builder {
180180
this.statistics = JobStatistics.fromPb(jobPb);
181181
}
182182
this.userEmail = jobPb.getUserEmail();
183-
this.configuration = JobConfiguration.fromPb(jobPb.getConfiguration());
183+
if (jobPb.getConfiguration() != null) {
184+
this.configuration = JobConfiguration.fromPb(jobPb.getConfiguration());
185+
}
184186
}
185187

186188
@Override
@@ -375,7 +377,9 @@ Job toPb() {
375377
if (statistics != null) {
376378
jobPb.setStatistics(statistics.toPb());
377379
}
378-
jobPb.setConfiguration(configuration.toPb());
380+
if(configuration != null){
381+
jobPb.setConfiguration(configuration.toPb());
382+
}
379383
return jobPb;
380384
}
381385

google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/JobTest.java

+10
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,16 @@ public void testToAndFromPb() {
523523
compareJob(expectedJob, Job.fromPb(serviceMockReturnsOptions, expectedJob.toPb()));
524524
}
525525

526+
@Test
527+
public void testToAndFromPbWithoutConfiguration() {
528+
JobInfo jobInfo =
529+
JobInfo.newBuilder(null)
530+
.build();
531+
initializeExpectedJob(4, jobInfo);
532+
replay(bigquery);
533+
compareJob(expectedJob, Job.fromPb(serviceMockReturnsOptions, expectedJob.toPb()));
534+
}
535+
526536
private void compareJob(Job expected, Job value) {
527537
assertEquals(expected, value);
528538
compareJobInfo(expected, value);

0 commit comments

Comments
 (0)