Skip to content

Commit 741fe90

Browse files
Merge pull request #1541 from data-integrations/gcs-npe-bug
[PLUGIN-1846] Fixed NPE on GCSSource when bucket does not exist
2 parents d6dbdb7 + a948b97 commit 741fe90

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/main/java/io/cdap/plugin/gcp/gcs/source/GCSSource.java

+12-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package io.cdap.plugin.gcp.gcs.source;
1818

1919
import com.google.auth.Credentials;
20+
import com.google.cloud.storage.Bucket;
2021
import com.google.cloud.storage.Storage;
2122
import com.google.cloud.storage.StorageException;
2223
import com.google.common.base.Strings;
@@ -55,6 +56,7 @@
5556
import java.util.HashMap;
5657
import java.util.List;
5758
import java.util.Map;
59+
import java.util.Objects;
5860
import java.util.regex.Pattern;
5961
import javax.annotation.Nullable;
6062

@@ -122,7 +124,16 @@ public void prepareRun(BatchSourceContext context) throws Exception {
122124
String location = null;
123125
try {
124126
// Get location of the source for lineage
125-
location = storage.get(bucketName).getLocation();
127+
Bucket bucket = storage.get(bucketName);
128+
if (Objects.isNull(bucket)) {
129+
String errorReason = String.format("Unable to access GCS bucket '%s'.",
130+
bucketName);
131+
collector.addFailure(
132+
String.format("%s Ensure you entered the correct bucket path.", errorReason),
133+
null);
134+
collector.getOrThrowException();
135+
}
136+
location = bucket.getLocation();
126137
} catch (StorageException e) {
127138
String errorReason = String.format("Error code: %s, Unable to access GCS bucket '%s'. ",
128139
e.getCode(), bucketName);

0 commit comments

Comments
 (0)