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
--- 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;
}