Bug 1290014 - DiskStorage: Do not use StandardCharsets.UTF_8. It's only support on API level 19+. r=ahunt
authorSebastian Kaspari <s.kaspari@gmail.com>
Thu, 18 Aug 2016 18:15:15 +0200
changeset 312474 ef83714d122603b428cede37fd3341375f61c6ed
parent 312473 f11ee12c87bbfeab4b25b4b30c9aa0f7aefc982c
child 312475 38d0defa2db77fa8bf209cf60bde4232896660cc
push id20447
push userkwierso@gmail.com
push dateFri, 02 Sep 2016 20:36:44 +0000
treeherderfx-team@969397f22187 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersahunt
bugs1290014
milestone51.0a1
Bug 1290014 - DiskStorage: Do not use StandardCharsets.UTF_8. It's only support on API level 19+. r=ahunt MozReview-Commit-ID: 5wvR4dgiPoJ
mobile/android/base/java/org/mozilla/gecko/icons/storage/DiskStorage.java
--- a/mobile/android/base/java/org/mozilla/gecko/icons/storage/DiskStorage.java
+++ b/mobile/android/base/java/org/mozilla/gecko/icons/storage/DiskStorage.java
@@ -19,17 +19,17 @@ import org.mozilla.gecko.icons.IconReque
 import org.mozilla.gecko.icons.IconResponse;
 import org.mozilla.gecko.sync.Utils;
 import org.mozilla.gecko.util.IOUtils;
 
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
-import java.nio.charset.StandardCharsets;
+import java.io.UnsupportedEncodingException;
 import java.security.MessageDigest;
 
 /**
  * Least Recently Used (LRU) disk cache for icons and the mappings from page URLs to icon URLs.
  */
 public class DiskStorage {
     private static final String LOGTAG = "Gecko/DiskStorage";
 
@@ -251,35 +251,37 @@ public class DiskStorage {
         try {
             // We use our own crypto implementation to avoid the penalty of loading the java crypto
             // framework.
             byte[] ctx = NativeCrypto.sha256init();
             if (ctx == null) {
                 return null;
             }
 
-            byte[] data = prefix.getBytes(StandardCharsets.UTF_8);
+            byte[] data = prefix.getBytes("UTF-8");
             NativeCrypto.sha256update(ctx, data, data.length);
 
-            data = url.getBytes(StandardCharsets.UTF_8);
+            data = url.getBytes("UTF-8");
             NativeCrypto.sha256update(ctx, data, data.length);
             return Utils.byte2Hex(NativeCrypto.sha256finalize(ctx));
         } catch (NoClassDefFoundError | ExceptionInInitializerError error) {
             // We could not load libmozglue.so. Let's use Java's MessageDigest as fallback. We do
             // this primarily for our unit tests that can't load native libraries. On an device
             // we will have a lot of other problems if we can't load libmozglue.so
             try {
                 MessageDigest md = MessageDigest.getInstance("SHA-256");
-                md.update(prefix.getBytes(StandardCharsets.UTF_8));
-                md.update(url.getBytes(StandardCharsets.UTF_8));
+                md.update(prefix.getBytes("UTF-8"));
+                md.update(url.getBytes("UTF-8"));
                 return Utils.byte2Hex(md.digest());
             } catch (Exception e) {
                 // Just give up. And let everyone know.
                 throw new RuntimeException(e);
             }
+        } catch (UnsupportedEncodingException e) {
+            throw new AssertionError("Should not happen: Device does not understand UTF-8");
         }
     }
 
     private void abortSilently(DiskLruCache.Editor editor) {
         if (editor != null) {
             try {
                 editor.abort();
             } catch (IOException e) {