Merge pull request #6778 from Stypox/invalid-storage-npe

Fix NullPointerException when checking if storage exists
This commit is contained in:
Tobi 2021-07-28 16:54:57 +02:00 committed by GitHub
commit cd713db029
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -8,6 +8,7 @@ import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.provider.DocumentsContract;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@ -15,6 +16,7 @@ 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;
@ -27,6 +29,9 @@ import us.shandian.giga.io.FileStream;
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";
@ -285,7 +290,13 @@ public class StoredFileHelper implements Serializable {
}
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;
}

View File

@ -664,7 +664,7 @@ public class DownloadMission extends Mission {
* @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();
}
/**