Merge branch 'fix-exception-logging' into 'master'

Don't warn about background exceptions unless one was thrown

See merge request briar/briar!1610
This commit is contained in:
akwizgran
2022-04-01 11:15:33 +00:00

View File

@@ -4,11 +4,11 @@ import org.junit.After;
import org.junit.Before;
import java.lang.Thread.UncaughtExceptionHandler;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.Nullable;
import static java.util.logging.Level.WARNING;
import static java.util.logging.Logger.getLogger;
public abstract class BrambleTestCase {
@@ -22,7 +22,7 @@ public abstract class BrambleTestCase {
public BrambleTestCase() {
// Ensure exceptions thrown on worker threads cause tests to fail
UncaughtExceptionHandler fail = (thread, throwable) -> {
LOG.log(Level.WARNING, "Caught unhandled exception", throwable);
LOG.log(WARNING, "Caught unhandled exception", throwable);
exceptionInBackgroundThread = throwable;
};
Thread.setDefaultUncaughtExceptionHandler(fail);
@@ -36,7 +36,11 @@ public abstract class BrambleTestCase {
@After
public void afterBrambleTestCase() {
Throwable thrown = exceptionInBackgroundThread;
LOG.warning("background thread has thrown an exception unexpectedly");
if (thrown != null) throw new AssertionError(thrown);
if (thrown != null) {
LOG.log(WARNING,
"Background thread has thrown an exception unexpectedly",
thrown);
throw new AssertionError(thrown);
}
}
}