Niedzielski has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/316496

Change subject: Hygiene: make Uri Exception handling more granular
......................................................................

Hygiene: make Uri Exception handling more granular

Catch all exception handlers should be rare. Clarify impossible states
by crashing.

Change-Id: I6b926b45163b955754ff4b7fc99c196ec32837b7
---
M app/src/main/java/org/wikipedia/util/UriUtil.java
1 file changed, 10 insertions(+), 7 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/apps/android/wikipedia 
refs/changes/96/316496/1

diff --git a/app/src/main/java/org/wikipedia/util/UriUtil.java 
b/app/src/main/java/org/wikipedia/util/UriUtil.java
index 74e310d..485dbda 100644
--- a/app/src/main/java/org/wikipedia/util/UriUtil.java
+++ b/app/src/main/java/org/wikipedia/util/UriUtil.java
@@ -10,14 +10,15 @@
 import android.support.annotation.StringRes;
 import android.support.annotation.VisibleForTesting;
 import android.text.TextUtils;
-import android.util.Log;
 
 import org.wikipedia.R;
 import org.wikipedia.WikipediaApp;
 import org.wikipedia.page.PageTitle;
 import org.wikipedia.settings.Prefs;
+import org.wikipedia.util.log.L;
 import org.wikipedia.zero.WikipediaZeroHandler;
 
+import java.io.UnsupportedEncodingException;
 import java.net.URLDecoder;
 
 import static 
org.wikipedia.zero.WikipediaZeroHandler.showZeroExitInterstitialDialog;
@@ -25,19 +26,21 @@
 public final class UriUtil {
 
     /**
-     * Decodes a URL-encoded string into its UTF-8 equivalent.
+     * Decodes a URL-encoded string into its UTF-8 equivalent. If the string 
cannot be decoded, the
+     * original string is returned.
      * @param url The URL-encoded string that you wish to decode.
      * @return The decoded string, or the input string if the decoding failed.
      */
     @NonNull public static String decodeURL(@NonNull String url) {
         try {
             return URLDecoder.decode(url, "UTF-8");
-        } catch (Exception e) {
-            // Swallow any exception, including UnsupportedEncodingException 
(shouldn't happen),
-            // and IllegalArgumentException (can happen with malformed 
encoding), and just return
-            // the original string.
-            Log.d("Wikipedia", "URL decoding failed. String was: " + url);
+        } catch (IllegalArgumentException e) {
+            // Swallow IllegalArgumentException (can happen with malformed 
encoding), and just
+            // return the original string.
+            L.d("URL decoding failed. String was: " + url);
             return url;
+        } catch (UnsupportedEncodingException e) {
+            throw new RuntimeException(e);
         }
     }
 

-- 
To view, visit https://gerrit.wikimedia.org/r/316496
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6b926b45163b955754ff4b7fc99c196ec32837b7
Gerrit-PatchSet: 1
Gerrit-Project: apps/android/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Niedzielski <sniedziel...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to