Skip to content

Commit

Permalink
fix: nullpointerexception for listroutines and listmodels (#890)
Browse files Browse the repository at this point in the history
  • Loading branch information
Praful Makani authored Oct 30, 2020
1 parent 4598f6d commit 9e5c7c7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,8 @@ public Tuple<String, Iterable<Model>> listModels(
.setMaxResults(Option.MAX_RESULTS.getLong(options))
.setPageToken(Option.PAGE_TOKEN.getString(options))
.execute();
Iterable<Model> models = modelList.getModels();
Iterable<Model> models =
modelList.getModels() != null ? modelList.getModels() : ImmutableList.<Model>of();
return Tuple.of(modelList.getNextPageToken(), models);
} catch (IOException ex) {
throw translate(ex);
Expand Down Expand Up @@ -456,7 +457,10 @@ public Tuple<String, Iterable<Routine>> listRoutines(
.setMaxResults(Option.MAX_RESULTS.getLong(options))
.setPageToken(Option.PAGE_TOKEN.getString(options))
.execute();
Iterable<Routine> routines = routineList.getRoutines();
Iterable<Routine> routines =
routineList.getRoutines() != null
? routineList.getRoutines()
: ImmutableList.<Routine>of();
return Tuple.of(routineList.getNextPageToken(), routines);
} catch (IOException ex) {
throw translate(ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ public class ITBigQueryTest {
private static final String MODEL_DATASET = RemoteBigQueryHelper.generateDatasetName();
private static final String ROUTINE_DATASET = RemoteBigQueryHelper.generateDatasetName();
private static final String PROJECT_ID = ServiceOptions.getDefaultProjectId();
private static final String RANDOM_ID = UUID.randomUUID().toString().substring(0, 8);
private static final Map<String, String> LABELS =
ImmutableMap.of(
"example-label1", "example-value1",
Expand Down Expand Up @@ -1425,6 +1426,29 @@ public void testModelLifecycle() throws InterruptedException {
assertTrue(bigquery.delete(modelId));
}

@Test
public void testEmptyListModels() {
String datasetId = "test_empty_dataset_list_models_" + RANDOM_ID;
assertNotNull(bigquery.create(DatasetInfo.of(datasetId)));
Page<Model> models = bigquery.listModels(datasetId, BigQuery.ModelListOption.pageSize(100));
assertEquals(0, Iterables.size(models.getValues()));
assertFalse(models.hasNextPage());
assertNull(models.getNextPageToken());
assertTrue(bigquery.delete(datasetId));
}

@Test
public void testEmptyListRoutines() {
String datasetId = "test_empty_dataset_list_routines_" + RANDOM_ID;
assertNotNull(bigquery.create(DatasetInfo.of(datasetId)));
Page<Routine> routines =
bigquery.listRoutines(datasetId, BigQuery.RoutineListOption.pageSize(100));
assertEquals(0, Iterables.size(routines.getValues()));
assertFalse(routines.hasNextPage());
assertNull(routines.getNextPageToken());
assertTrue(bigquery.delete(datasetId));
}

@Test
public void testRoutineLifecycle() throws InterruptedException {

Expand Down

0 comments on commit 9e5c7c7

Please sign in to comment.