Skip to content
Permalink
Browse files
fix: nullpointerexception for listroutines and listmodels (#890)
  • Loading branch information
Praful Makani committed Oct 30, 2020
1 parent 4598f6d commit 9e5c7c7a6a0e32ce145a727bcdc1493e149f3b14
@@ -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);
@@ -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);
@@ -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",
@@ -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 {

0 comments on commit 9e5c7c7

Please sign in to comment.