Bug 1289006 - Return gracefully if listFiles returns null in telemetry store. r=grisha draft
authorMichael Comella <michael.l.comella@gmail.com>
Mon, 25 Jul 2016 13:57:45 -0700
changeset 392630 15d0c4a3d283924627f1f97a1f99637244c49c08
parent 390759 bd6655e7b879214b7d983ca85c8160a77a653178
child 392631 8290e515c9010bef639e92d1b0420bebe5c7d61c
push id24061
push usermichael.l.comella@gmail.com
push dateMon, 25 Jul 2016 21:27:56 +0000
reviewersgrisha
bugs1289006
milestone50.0a1
Bug 1289006 - Return gracefully if listFiles returns null in telemetry store. r=grisha This changeset will correct the crash we're seeing in the bug. The docs support that File.listFiles can return null. MozReview-Commit-ID: FHYGErshhoP
mobile/android/base/java/org/mozilla/gecko/telemetry/stores/TelemetryJSONFilePingStore.java
--- a/mobile/android/base/java/org/mozilla/gecko/telemetry/stores/TelemetryJSONFilePingStore.java
+++ b/mobile/android/base/java/org/mozilla/gecko/telemetry/stores/TelemetryJSONFilePingStore.java
@@ -124,17 +124,25 @@ public class TelemetryJSONFilePingStore 
             // Sorted set so we're iterating over ascending files.
             final File file = it.next(); // file count > files to remove so this should not throw.
             file.delete();
         }
     }
 
     @Override
     public ArrayList<TelemetryPing> getAllPings() {
-        final List<File> files = Arrays.asList(storeDir.listFiles(uuidFilenameFilter));
+        final File[] fileArray = storeDir.listFiles(uuidFilenameFilter);
+        if (fileArray == null) {
+            // Intentionally don't log all info for the store directory to prevent leaking the path.
+            Log.w(LOGTAG, "listFiles unexpectedly returned null - unable to retrieve pings. Debug: exists? " +
+                    storeDir.exists() + "; directory? " + storeDir.isDirectory());
+            return new ArrayList<>(1);
+        }
+
+        final List<File> files = Arrays.asList(fileArray);
         Collections.sort(files, fileLastModifiedComparator); // oldest to newest
         final ArrayList<TelemetryPing> out = new ArrayList<>(files.size());
         for (final File file : files) {
             final JSONObject obj = lockAndReadJSONFromFile(file);
             if (obj == null) {
                 // We log in the method to get the JSONObject if we return null.
                 continue;
             }