Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NullPointerException when checking if storage exists #6778

Merged
merged 2 commits into from
Jul 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Stypox marked this conversation as resolved.
Show resolved Hide resolved
}

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