Avoid NPE when _DATA column is empty.
Jeff Sharkey [Fri, 20 Apr 2012 18:53:48 +0000 (11:53 -0700)]
Bug: 6371718
Change-Id: Id661210101b01daf8f5d46a318c32dbb9de9a4fb

src/com/android/providers/downloads/StorageManager.java

index 4f3af5c..19132b5 100644 (file)
@@ -329,8 +329,12 @@ class StorageManager {
         }
         long totalFreed = 0;
         try {
+            final int dataIndex = cursor.getColumnIndex(Downloads.Impl._DATA);
             while (cursor.moveToNext() && totalFreed < targetBytes) {
-                File file = new File(cursor.getString(cursor.getColumnIndex(Downloads.Impl._DATA)));
+                final String data = cursor.getString(dataIndex);
+                if (TextUtils.isEmpty(data)) continue;
+
+                File file = new File(data);
                 if (true || Constants.LOGV) {
                     Slog.d(Constants.TAG, "purging " + file.getAbsolutePath() + " for " +
                             file.length() + " bytes");