Skip to content

Commit cd713db

Browse files
authored
Merge pull request #6778 from Stypox/invalid-storage-npe
Fix NullPointerException when checking if storage exists
2 parents 5924edb + 2aebf6c commit cd713db

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

app/src/main/java/org/schabi/newpipe/streams/io/StoredFileHelper.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
88
import android.os.Build;
99
import android.os.Environment;
1010
import android.provider.DocumentsContract;
11+
import android.util.Log;
1112

1213
import androidx.annotation.NonNull;
1314
import androidx.annotation.Nullable;
1415
import androidx.documentfile.provider.DocumentFile;
1516

1617
import com.nononsenseapps.filepicker.Utils;
1718

19+
import org.schabi.newpipe.MainActivity;
1820
import org.schabi.newpipe.settings.NewPipeSettings;
1921
import org.schabi.newpipe.util.FilePickerActivityHelper;
2022

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

2931
public class StoredFileHelper implements Serializable {
32+
private static final boolean DEBUG = MainActivity.DEBUG;
33+
private static final String TAG = StoredFileHelper.class.getSimpleName();
34+
3035
private static final long serialVersionUID = 0L;
3136
public static final String DEFAULT_MIME = "application/octet-stream";
3237

@@ -285,7 +290,13 @@ public String getTag() {
285290
}
286291

287292
public boolean existsAsFile() {
288-
if (source == null) {
293+
if (source == null || (docFile == null && ioFile == null)) {
294+
if (DEBUG) {
295+
Log.d(TAG, "existsAsFile called but something is null: source = ["
296+
+ (source == null ? "null => storage is invalid" : source)
297+
+ "], docFile = [" + (docFile == null ? "null" : docFile)
298+
+ "], ioFile = [" + (ioFile == null ? "null" : ioFile) + "]");
299+
}
289300
return false;
290301
}
291302

app/src/main/java/us/shandian/giga/get/DownloadMission.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ public void psContinue(boolean recover) {
664664
* @return {@code true}, if storage is invalid and cannot be used
665665
*/
666666
public boolean hasInvalidStorage() {
667-
return errCode == ERROR_PROGRESS_LOST || storage == null || storage.isInvalid() || !storage.existsAsFile();
667+
return errCode == ERROR_PROGRESS_LOST || storage == null || !storage.existsAsFile();
668668
}
669669

670670
/**

0 commit comments

Comments
 (0)