Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

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
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -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;
+10 −0
Original line number Diff line number Diff line
@@ -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());
    }
}