From 9ae66cc74712dc14917b399c73fd2aabd9b72e52 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Sun, 18 Jan 2015 18:57:08 +0100 Subject: [PATCH] Use Exception.getString in HostAddress instead of getMessage(), because some Exceptions, e.g. Android's NetworkOnMainThreadException, will return null on getMessage(). Exception.toString() does what we want, i.e. returns - the exception class name - and the return value of getLocalizedMessage() --- .../java/org/jivesoftware/smack/util/dns/HostAddress.java | 8 ++------ .../java/org/jivesoftware/smack/SmackExceptionTest.java | 2 +- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/dns/HostAddress.java b/smack-core/src/main/java/org/jivesoftware/smack/util/dns/HostAddress.java index 9b34239e5..f0004b520 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/util/dns/HostAddress.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/util/dns/HostAddress.java @@ -109,13 +109,9 @@ public class HostAddress { } public String getErrorMessage() { - String error; if (exception == null) { - error = "No error logged"; + return "No error logged"; } - else { - error = exception.getMessage(); - } - return toString() + " Exception: " + error; + return "'" + toString() + "' failed because " + exception.toString(); } } diff --git a/smack-core/src/test/java/org/jivesoftware/smack/SmackExceptionTest.java b/smack-core/src/test/java/org/jivesoftware/smack/SmackExceptionTest.java index ec6013a8f..498a17cb9 100644 --- a/smack-core/src/test/java/org/jivesoftware/smack/SmackExceptionTest.java +++ b/smack-core/src/test/java/org/jivesoftware/smack/SmackExceptionTest.java @@ -41,7 +41,7 @@ public class SmackExceptionTest { ConnectionException connectionException = ConnectionException.from(failedAddresses); String message = connectionException.getMessage(); - assertEquals("The following addresses failed: foo.bar.example:1234 Exception: Failed for some reason, barz.example:5678 Exception: Failed for some other reason", + assertEquals("The following addresses failed: 'foo.bar.example:1234' failed because java.lang.Exception: Failed for some reason, 'barz.example:5678' failed because java.lang.Exception: Failed for some other reason", message); }