From 9c8d7af3bfd42ffdc37c95dab9665aeb7482d1d1 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Tue, 18 Mar 2014 11:19:37 +0100 Subject: [PATCH] Fix error handling in BOSHConnection getCause() never throws. Not sure why the code was written that way. Thanks to CSH for reporting. --- .../org/jivesoftware/smack/BOSHConnection.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/bosh/src/main/java/org/jivesoftware/smack/BOSHConnection.java b/bosh/src/main/java/org/jivesoftware/smack/BOSHConnection.java index b1b0af67b..382262e6c 100644 --- a/bosh/src/main/java/org/jivesoftware/smack/BOSHConnection.java +++ b/bosh/src/main/java/org/jivesoftware/smack/BOSHConnection.java @@ -590,12 +590,16 @@ public class BOSHConnection extends XMPPConnection { } else { if (connEvent.isError()) { - try { - connEvent.getCause(); - } - catch (Exception e) { - notifyConnectionError(e); + // TODO Check why jbosh's getCause returns Throwable here. This is very + // unusual and should be avoided if possible + Throwable cause = connEvent.getCause(); + Exception e; + if (cause instanceof Exception) { + e = (Exception) cause; + } else { + e = new Exception(cause); } + notifyConnectionError(e); } connected = false; }