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

--HG--
extra : rebase_source : 15d0c4a3d283924627f1f97a1f99637244c49c08
This commit is contained in:
Michael Comella 2016-07-25 13:57:45 -07:00
Родитель cccfcddf71
Коммит bd05d8b08b
1 изменённых файлов: 9 добавлений и 1 удалений

Просмотреть файл

@ -129,7 +129,15 @@ public class TelemetryJSONFilePingStore extends TelemetryPingStore {
@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) {