Fix NullPointerException: Attempt to get length of null array in MainActivity (#5999)

* Fixed Unable to start activity ComponentInfo{org.schabi.newpipe/org.schabi.newpipe.MainActivity}: java.lang.NullPointerException: Attempt to get length of null array #5996
issue : #5996
changed :
- Checked null
This commit is contained in:
wangear 2021-04-06 21:13:13 +09:00 committed by GitHub
parent 4d74be881d
commit 5d5f8b4d51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 6 deletions

View File

@ -72,10 +72,10 @@ public final class StateSaver {
} }
/** /**
* @see #tryToRestore(SavedState, WriteRead)
* @param outState * @param outState
* @param writeRead * @param writeRead
* @return the saved state * @return the saved state
* @see #tryToRestore(SavedState, WriteRead)
*/ */
public static SavedState tryToRestore(final Bundle outState, final WriteRead writeRead) { public static SavedState tryToRestore(final Bundle outState, final WriteRead writeRead) {
if (outState == null || writeRead == null) { if (outState == null || writeRead == null) {
@ -93,6 +93,7 @@ public final class StateSaver {
/** /**
* Try to restore the state from memory and disk, * Try to restore the state from memory and disk,
* using the {@link StateSaver.WriteRead#readFrom(Queue)} from the writeRead. * using the {@link StateSaver.WriteRead#readFrom(Queue)} from the writeRead.
*
* @param savedState * @param savedState
* @param writeRead * @param writeRead
* @return the saved state * @return the saved state
@ -143,19 +144,18 @@ public final class StateSaver {
} }
/** /**
* @see #tryToSave(boolean, String, String, WriteRead)
* @param isChangingConfig * @param isChangingConfig
* @param savedState * @param savedState
* @param outState * @param outState
* @param writeRead * @param writeRead
* @return the saved state or {@code null} * @return the saved state or {@code null}
* @see #tryToSave(boolean, String, String, WriteRead)
*/ */
@Nullable @Nullable
public static SavedState tryToSave(final boolean isChangingConfig, public static SavedState tryToSave(final boolean isChangingConfig,
@Nullable final SavedState savedState, final Bundle outState, @Nullable final SavedState savedState, final Bundle outState,
final WriteRead writeRead) { final WriteRead writeRead) {
@NonNull @NonNull final String currentSavedPrefix;
final String currentSavedPrefix;
if (savedState == null || TextUtils.isEmpty(savedState.getPrefixFileSaved())) { if (savedState == null || TextUtils.isEmpty(savedState.getPrefixFileSaved())) {
// Generate unique prefix // Generate unique prefix
currentSavedPrefix = System.nanoTime() - writeRead.hashCode() + ""; currentSavedPrefix = System.nanoTime() - writeRead.hashCode() + "";
@ -299,8 +299,11 @@ public final class StateSaver {
cacheDir = new File(cacheDir, CACHE_DIR_NAME); cacheDir = new File(cacheDir, CACHE_DIR_NAME);
if (cacheDir.exists()) { if (cacheDir.exists()) {
for (final File file : cacheDir.listFiles()) { final File[] list = cacheDir.listFiles();
file.delete(); if (list != null) {
for (final File file : list) {
file.delete();
}
} }
} }
} }