mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-03-10 09:20:04 +01:00
GuiUtils: replace Guava Throwables.getRootCause()
with private helper method
Private helper walks up the chain and avoids loops.
This commit is contained in:
parent
66d96ab29d
commit
b7cf58ba6d
1 changed files with 11 additions and 3 deletions
|
@ -16,7 +16,6 @@
|
|||
|
||||
package org.bitcoinj.walletfx.utils;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
import javafx.animation.*;
|
||||
import javafx.application.Platform;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
|
@ -30,6 +29,7 @@ import javafx.util.Duration;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.Objects;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
import static org.bitcoinj.base.internal.Preconditions.checkState;
|
||||
|
@ -57,7 +57,7 @@ public class GuiUtils {
|
|||
|
||||
public static void crashAlert(Throwable t) {
|
||||
t.printStackTrace();
|
||||
Throwable rootCause = Throwables.getRootCause(t);
|
||||
Throwable rootCause = findRootCause(t);
|
||||
Runnable r = () -> {
|
||||
runAlert((stage, controller) -> controller.crashAlert(stage, rootCause.toString()));
|
||||
Platform.exit();
|
||||
|
@ -70,7 +70,7 @@ public class GuiUtils {
|
|||
|
||||
/** Show a GUI alert box for any unhandled exceptions that propagate out of this thread. */
|
||||
public static void handleCrashesOnThisThread() {
|
||||
Thread.currentThread().setUncaughtExceptionHandler((thread, exception) -> GuiUtils.crashAlert(Throwables.getRootCause(exception)));
|
||||
Thread.currentThread().setUncaughtExceptionHandler((thread, exception) -> GuiUtils.crashAlert(findRootCause(exception)));
|
||||
}
|
||||
|
||||
public static void informationalAlert(String message, String details, Object... args) {
|
||||
|
@ -181,4 +181,12 @@ public class GuiUtils {
|
|||
public static void checkGuiThread() {
|
||||
checkState(Platform.isFxApplicationThread());
|
||||
}
|
||||
|
||||
private static Throwable findRootCause(Throwable throwable) {
|
||||
Throwable rootCause = Objects.requireNonNull(throwable);
|
||||
while (rootCause.getCause() != null && rootCause.getCause() != rootCause) {
|
||||
rootCause = rootCause.getCause();
|
||||
}
|
||||
return rootCause;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue