Skip to content

Commit

Permalink
Merge pull request #6778 from Stypox/invalid-storage-npe
Browse files Browse the repository at this point in the history
Fix NullPointerException when checking if storage exists
  • Loading branch information
TobiGr authored Jul 28, 2021
2 parents 5924edb + 2aebf6c commit cd713db
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
import android.os.Build;
import android.os.Environment;
import android.provider.DocumentsContract;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.documentfile.provider.DocumentFile;

import com.nononsenseapps.filepicker.Utils;

import org.schabi.newpipe.MainActivity;
import org.schabi.newpipe.settings.NewPipeSettings;
import org.schabi.newpipe.util.FilePickerActivityHelper;

Expand All @@ -27,6 +29,9 @@
import us.shandian.giga.io.FileStreamSAF;

public class StoredFileHelper implements Serializable {
private static final boolean DEBUG = MainActivity.DEBUG;
private static final String TAG = StoredFileHelper.class.getSimpleName();

private static final long serialVersionUID = 0L;
public static final String DEFAULT_MIME = "application/octet-stream";

Expand Down Expand Up @@ -285,7 +290,13 @@ public String getTag() {
}

public boolean existsAsFile() {
if (source == null) {
if (source == null || (docFile == null && ioFile == null)) {
if (DEBUG) {
Log.d(TAG, "existsAsFile called but something is null: source = ["
+ (source == null ? "null => storage is invalid" : source)
+ "], docFile = [" + (docFile == null ? "null" : docFile)
+ "], ioFile = [" + (ioFile == null ? "null" : ioFile) + "]");
}
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ public void psContinue(boolean recover) {
* @return {@code true}, if storage is invalid and cannot be used
*/
public boolean hasInvalidStorage() {
return errCode == ERROR_PROGRESS_LOST || storage == null || storage.isInvalid() || !storage.existsAsFile();
return errCode == ERROR_PROGRESS_LOST || storage == null || !storage.existsAsFile();
}

/**
Expand Down

0 comments on commit cd713db

Please sign in to comment.