diff options
author | kang <kang@google.com> | 2014-02-27 14:09:01 -0500 |
---|---|---|
committer | kang <kang@google.com> | 2014-02-27 14:20:03 -0500 |
commit | 0ec9297ffdf80183d17ca61759ecc18eae9f8167 (patch) | |
tree | fd0d4c382c9743fff5c08ff113f9164e36cf4270 /src | |
parent | e542f4964d2b6668c028edce5afe1fe2faefc64b (diff) | |
download | volley-0ec9297ffdf80183d17ca61759ecc18eae9f8167.tar.gz |
Guard against NullPointerException currently
occurring in Volley when a Request is given a url whose host is null.
Change-Id: Idab1dadaa43bb9176356028221cbdc0f8dd52cdc
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/volley/Request.java | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/com/android/volley/Request.java b/src/com/android/volley/Request.java index 0e5912f..53093e6 100644 --- a/src/com/android/volley/Request.java +++ b/src/com/android/volley/Request.java @@ -134,7 +134,7 @@ public abstract class Request<T> implements Comparable<Request<T>> { mErrorListener = listener; setRetryPolicy(new DefaultRetryPolicy()); - mDefaultTrafficStatsTag = TextUtils.isEmpty(url) ? 0: Uri.parse(url).getHost().hashCode(); + mDefaultTrafficStatsTag = findDefaultTrafficStatsTag(url); } /** @@ -171,6 +171,22 @@ public abstract class Request<T> implements Comparable<Request<T>> { } /** + * @return The hashcode of the URL's host component, or 0 if there is none. + */ + private static int findDefaultTrafficStatsTag(String url) { + if (!TextUtils.isEmpty(url)) { + Uri uri = Uri.parse(url); + if (uri != null) { + String host = uri.getHost(); + if (host != null) { + return host.hashCode(); + } + } + } + return 0; + } + + /** * Sets the retry policy for this request. * * @return This Request object to allow for chaining. |