Skip to content

Commit 6df2784

Browse files
authored
return exception if modelname is empty (#4226)
1 parent 2253cd4 commit 6df2784

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

firebase-ml-modeldownloader/src/main/java/com/google/firebase/ml/modeldownloader/internal/CustomModelDownloadService.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import android.content.Context;
1818
import android.content.pm.PackageManager;
19+
import android.text.TextUtils;
1920
import android.util.JsonReader;
2021
import android.util.Log;
2122
import androidx.annotation.NonNull;
@@ -148,6 +149,12 @@ public Task<CustomModel> getNewDownloadUrlWithExpiry(String projectNumber, Strin
148149
public Task<CustomModel> getCustomModelDetails(
149150
String projectNumber, String modelName, String modelHash) {
150151
try {
152+
153+
if (TextUtils.isEmpty(modelName))
154+
throw new FirebaseMlException(
155+
"Error cannot retrieve model from reading an empty modelName",
156+
FirebaseMlException.INVALID_ARGUMENT);
157+
151158
URL url =
152159
new URL(String.format(DOWNLOAD_MODEL_REGEX, downloadHost, projectNumber, modelName));
153160
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
@@ -206,6 +213,8 @@ public Task<CustomModel> getCustomModelDetails(
206213
new FirebaseMlException(
207214
"Error reading custom model from download service: " + e.getMessage(),
208215
FirebaseMlException.INVALID_ARGUMENT));
216+
} catch (FirebaseMlException e) {
217+
return Tasks.forException(e);
209218
}
210219
}
211220

0 commit comments

Comments
 (0)