Skip to content
Snippets Groups Projects
Commit c850bdbe authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix NPE while reading leftover journals in BMS"

parents 0d20abc8 d1b4b816
No related branches found
No related tags found
No related merge requests found
......@@ -17,6 +17,7 @@
package com.android.server.backup;
import android.annotation.Nullable;
import android.util.Slog;
import java.io.BufferedInputStream;
import java.io.DataInputStream;
......@@ -36,6 +37,7 @@ import java.util.function.Consumer;
* reboot.
*/
public class DataChangedJournal {
private static final String TAG = "DataChangedJournal";
private static final String FILE_NAME_PREFIX = "journal";
/**
......@@ -139,7 +141,12 @@ public class DataChangedJournal {
*/
static ArrayList<DataChangedJournal> listJournals(File journalDirectory) {
ArrayList<DataChangedJournal> journals = new ArrayList<>();
for (File file : journalDirectory.listFiles()) {
File[] journalFiles = journalDirectory.listFiles();
if (journalFiles == null) {
Slog.w(TAG, "Failed to read journal files");
return journals;
}
for (File file : journalFiles) {
journals.add(new DataChangedJournal(file));
}
return journals;
......
......@@ -18,6 +18,9 @@ package com.android.server.backup;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.when;
import static org.testng.Assert.assertEquals;
import android.platform.test.annotations.Presubmit;
import androidx.test.filters.SmallTest;
......@@ -50,6 +53,7 @@ public class DataChangedJournalTest {
@Rule public TemporaryFolder mTemporaryFolder = new TemporaryFolder();
@Mock private Consumer<String> mConsumer;
@Mock private File invalidFile;
private File mFile;
private DataChangedJournal mJournal;
......@@ -131,4 +135,10 @@ public class DataChangedJournalTest {
public void toString_isSameAsFileToString() throws Exception {
assertThat(mJournal.toString()).isEqualTo(mFile.toString());
}
public void listJournals_invalidJournalFile_returnsEmptyList() throws Exception {
when(invalidFile.listFiles()).thenReturn(null);
assertEquals(0, DataChangedJournal.listJournals(invalidFile).size());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment