From ddb47c2d60e9a721068685603c8931f7e30c2654 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Mon, 28 Apr 2014 17:35:07 +0200 Subject: [PATCH] Don't throw XmlPullParserException removes the need to wrap the exception in a SmackException in XMPPTCPConnection.initConnection() --- .../org/jivesoftware/smack/PacketReader.java | 21 ++++++++++++------- .../jivesoftware/smack/XMPPTCPConnection.java | 4 ++-- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/tcp/src/main/java/org/jivesoftware/smack/PacketReader.java b/tcp/src/main/java/org/jivesoftware/smack/PacketReader.java index 87bb8ce77..7968da2c3 100644 --- a/tcp/src/main/java/org/jivesoftware/smack/PacketReader.java +++ b/tcp/src/main/java/org/jivesoftware/smack/PacketReader.java @@ -59,7 +59,7 @@ class PacketReader { volatile boolean done; - protected PacketReader(final XMPPTCPConnection connection) throws XmlPullParserException { + protected PacketReader(final XMPPTCPConnection connection) throws SmackException { this.connection = connection; this.init(); } @@ -68,9 +68,9 @@ class PacketReader { * Initializes the reader in order to be used. The reader is initialized during the * first connection and when reconnecting due to an abruptly disconnection. * - * @throws XmlPullParserException if the parser could not be reset. + * @throws SmackException if the parser could not be reset. */ - protected void init() throws XmlPullParserException { + protected void init() throws SmackException { done = false; lastFeaturesParsed = false; @@ -128,12 +128,17 @@ class PacketReader { * when the plain connection has been secured or when a new opening stream element is going * to be sent by the server. * - * @throws XmlPullParserException XmlPullParserException if the parser could not be reset. + * @throws SmackException if the parser could not be reset. */ - private void resetParser() throws XmlPullParserException { - parser = XmlPullParserFactory.newInstance().newPullParser(); - parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true); - parser.setInput(connection.reader); + private void resetParser() throws SmackException { + try { + parser = XmlPullParserFactory.newInstance().newPullParser(); + parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true); + parser.setInput(connection.reader); + } + catch (XmlPullParserException e) { + throw new SmackException(e); + } } /** diff --git a/tcp/src/main/java/org/jivesoftware/smack/XMPPTCPConnection.java b/tcp/src/main/java/org/jivesoftware/smack/XMPPTCPConnection.java index a7191ef85..07a826d12 100644 --- a/tcp/src/main/java/org/jivesoftware/smack/XMPPTCPConnection.java +++ b/tcp/src/main/java/org/jivesoftware/smack/XMPPTCPConnection.java @@ -518,7 +518,7 @@ public class XMPPTCPConnection extends XMPPConnection { } } - catch (Exception ex) { + catch (SmackException ex) { // An exception occurred in setting up the connection. Make sure we shut down the // readers and writers and close the socket. @@ -561,7 +561,7 @@ public class XMPPTCPConnection extends XMPPConnection { authenticated = false; connected = false; - throw new SmackException(ex); // Everything stoppped. Now throw the exception. + throw ex; // Everything stoppped. Now throw the exception. } }