Merge pull request #3349 from ByteHamster/no-crash-after-dispose

Do not crash on undeliverable InterruptedException
This commit is contained in:
H. Lehmann 2019-08-30 13:44:13 +02:00 committed by GitHub
commit 46af0e0c36
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 11 deletions

View File

@ -32,7 +32,6 @@ public class ItunesTopListLoader {
String lang = Locale.getDefault().getLanguage();
OkHttpClient client = AntennapodHttpClient.getHttpClient();
String feedString;
try {
try {
feedString = getTopListFeed(client, lang, limit);
} catch (IOException e) {
@ -40,9 +39,6 @@ public class ItunesTopListLoader {
}
List<PodcastSearchResult> podcasts = parseFeed(feedString);
emitter.onSuccess(podcasts);
} catch (IOException | JSONException e) {
emitter.onError(e);
}
})
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());

View File

@ -42,6 +42,7 @@ public class ClientConfig {
PlaybackPreferences.init(context);
NetworkUtils.init(context);
SleepTimerPreferences.init(context);
RxJavaErrorHandlerSetup.setupRxJavaErrorHandler();
initialized = true;
}

View File

@ -0,0 +1,26 @@
package de.danoeh.antennapod.core.util.exception;
import android.util.Log;
import io.reactivex.exceptions.UndeliverableException;
import io.reactivex.plugins.RxJavaPlugins;
public class RxJavaErrorHandlerSetup {
private RxJavaErrorHandlerSetup() {
}
public static void setupRxJavaErrorHandler() {
RxJavaPlugins.setErrorHandler(e -> {
if (e instanceof UndeliverableException) {
e = e.getCause();
}
if (e instanceof InterruptedException) {
// fine, some blocking code was interrupted by a dispose call
Log.d("RxJavaErrorHandler", "Ignored exception: " + Log.getStackTraceString(e));
return;
}
Thread.currentThread().getUncaughtExceptionHandler().uncaughtException(Thread.currentThread(), e);
});
}
}

View File

@ -8,6 +8,7 @@ import de.danoeh.antennapod.core.preferences.SleepTimerPreferences;
import de.danoeh.antennapod.core.preferences.UserPreferences;
import de.danoeh.antennapod.core.storage.PodDBAdapter;
import de.danoeh.antennapod.core.util.NetworkUtils;
import de.danoeh.antennapod.core.util.exception.RxJavaErrorHandlerSetup;
/**
* Stores callbacks for core classes like Services, DB classes etc. and other configuration variables.
@ -45,6 +46,7 @@ public class ClientConfig {
NetworkUtils.init(context);
CastManager.init(context);
SleepTimerPreferences.init(context);
RxJavaErrorHandlerSetup.setupRxJavaErrorHandler();
initialized = true;
}