From 3d1a781a2228d9d2fe31f6b8c96687ca3dc56eb5 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Tue, 5 Mar 2019 08:21:59 +0100 Subject: [PATCH] Show correct reply timeout value in StanzaCollector's NoResponseException --- .../org/jivesoftware/smack/SmackException.java | 18 ++++++++++++++++-- .../jivesoftware/smack/StanzaCollector.java | 2 +- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/smack-core/src/main/java/org/jivesoftware/smack/SmackException.java b/smack-core/src/main/java/org/jivesoftware/smack/SmackException.java index a84b75211..3011a1288 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/SmackException.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/SmackException.java @@ -93,13 +93,24 @@ public class SmackException extends Exception { return new NoResponseException(sb.toString()); } + @Deprecated + // TODO: Remove in Smack 4.4. public static NoResponseException newWith(XMPPConnection connection, StanzaCollector collector) { return newWith(connection, collector.getStanzaFilter()); } + public static NoResponseException newWith(long timeout, + StanzaCollector collector) { + return newWith(timeout, collector.getStanzaFilter()); + } + public static NoResponseException newWith(XMPPConnection connection, StanzaFilter filter) { - final StringBuilder sb = getWaitingFor(connection); + return newWith(connection.getReplyTimeout(), filter); + } + + public static NoResponseException newWith(long timeout, StanzaFilter filter) { + final StringBuilder sb = getWaitingFor(timeout); sb.append(" Waited for response using: "); if (filter != null) { sb.append(filter.toString()); @@ -112,7 +123,10 @@ public class SmackException extends Exception { } private static StringBuilder getWaitingFor(XMPPConnection connection) { - final long replyTimeout = connection.getReplyTimeout(); + return getWaitingFor(connection.getReplyTimeout()); + } + + private static StringBuilder getWaitingFor(final long replyTimeout) { final StringBuilder sb = new StringBuilder(256); sb.append("No response received within reply timeout. Timeout was " + replyTimeout + "ms (~" diff --git a/smack-core/src/main/java/org/jivesoftware/smack/StanzaCollector.java b/smack-core/src/main/java/org/jivesoftware/smack/StanzaCollector.java index 0b933909e..f6aa5225c 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/StanzaCollector.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/StanzaCollector.java @@ -262,7 +262,7 @@ public class StanzaCollector { if (!connection.isConnected()) { throw new NotConnectedException(connection, packetFilter); } - throw NoResponseException.newWith(connection, this); + throw NoResponseException.newWith(timeout, this); } XMPPErrorException.ifHasErrorThenThrow(result);