ExceptionLoggers: never have a null message

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jason A. Donenfeld
2018-05-16 17:36:25 +02:00
parent 9c3091456d
commit 694577b9b4
6 changed files with 20 additions and 11 deletions
@@ -6,8 +6,8 @@
package com.wireguard.android.util;
import android.support.annotation.NonNull;
import android.util.Log;
import java9.util.concurrent.CompletionException;
import java9.util.function.BiConsumer;
@@ -29,11 +29,20 @@ public enum ExceptionLoggers implements BiConsumer<Object, Throwable> {
}
public static Throwable unwrap(final Throwable throwable) {
if (throwable instanceof CompletionException)
if (throwable instanceof CompletionException && throwable.getCause() != null)
return throwable.getCause();
return throwable;
}
@NonNull
public static String unwrapMessage(Throwable throwable) {
throwable = unwrap(throwable);
final String message = throwable.getMessage();
if (message != null)
return message;
return throwable.getClass().getSimpleName();
}
@Override
public void accept(final Object result, final Throwable throwable) {
if (throwable != null)