Bug 1318560 - ColorProcessor: Handle ArrayIndexOutOfBoundsException from Palette library. r?gbrown,maliu draft
authorSebastian Kaspari <s.kaspari@gmail.com>
Mon, 21 Nov 2016 18:00:01 +0100
changeset 442380 094d44084f6e2a4dc1365d681aeec11df2f028ae
parent 442068 0534254e9a40b4bade2577c631fe4cfa0b5db41d
child 537789 d2b61e661e0966479d4cc36c35decd31442a43a8
push id36692
push users.kaspari@gmail.com
push dateTue, 22 Nov 2016 11:46:19 +0000
reviewersgbrown, maliu
bugs1318560
milestone53.0a1
Bug 1318560 - ColorProcessor: Handle ArrayIndexOutOfBoundsException from Palette library. r?gbrown,maliu MozReview-Commit-ID: GwYj1SRNytN
mobile/android/base/java/org/mozilla/gecko/icons/processing/ColorProcessor.java
--- a/mobile/android/base/java/org/mozilla/gecko/icons/processing/ColorProcessor.java
+++ b/mobile/android/base/java/org/mozilla/gecko/icons/processing/ColorProcessor.java
@@ -1,30 +1,41 @@
 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko.icons.processing;
 
 import android.support.v7.graphics.Palette;
+import android.util.Log;
 
+import org.mozilla.gecko.gfx.BitmapUtils;
 import org.mozilla.gecko.icons.IconRequest;
 import org.mozilla.gecko.icons.IconResponse;
 
 /**
  * Processor implementation to extract the dominant color from the icon and attach it to the icon
  * response object.
  */
 public class ColorProcessor implements Processor {
+    private static final String LOGTAG = "GeckoColorProcessor";
     private static final int DEFAULT_COLOR = 0; // 0 == No color
 
     @Override
     public void process(IconRequest request, IconResponse response) {
         if (response.hasColor()) {
             return;
         }
 
-        final Palette palette = Palette.from(response.getBitmap()).generate();
+        try {
+            final Palette palette = Palette.from(response.getBitmap()).generate();
+            response.updateColor(palette.getVibrantColor(DEFAULT_COLOR));
+        } catch (ArrayIndexOutOfBoundsException e) {
+            // We saw the palette library fail with an ArrayIndexOutOfBoundsException intermittently
+            // in automation. In this case lets just swallow the exception and move on without a
+            // color. This is a valid condition and callers should handle this gracefully (Bug 1318560).
+            Log.e(LOGTAG, "Palette generation failed with ArrayIndexOutOfBoundsException", e);
 
-        response.updateColor(palette.getVibrantColor(DEFAULT_COLOR));
+            response.updateColor(DEFAULT_COLOR);
+        }
     }
 }