diff --git a/.gitignore b/.gitignore
index 8eeb443be..989af3d92 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,8 @@
# IntelliJ
.idea
*.iml
+*.ipr
+*.iws
# Mac OS X
.DS_Store
diff --git a/.travis.yml b/.travis.yml
index 41f447858..969285456 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -10,7 +10,7 @@ cache:
- $HOME/.m2
before_install:
- - export GRADLE_VERSION=2.12
+ - export GRADLE_VERSION=3.5
- wget https://services.gradle.org/distributions/gradle-${GRADLE_VERSION}-all.zip
- unzip -q gradle-${GRADLE_VERSION}-all.zip
- export PATH="$(pwd)/gradle-${GRADLE_VERSION}/bin:$PATH"
@@ -19,6 +19,6 @@ install: gradle assemble --stacktrace
script: gradle check --stacktrace
after_success:
-- JAVAC_VERSION=$((javac -version) 2>&1)
-# Only run jacocoRootReport in the Java7 build
-- if [[ "$JAVAC_VERSION" = javac\ 1.7.* ]]; then gradle jacocoRootReport coveralls; fi
+ - JAVAC_VERSION=$((javac -version) 2>&1)
+ # Only run jacocoRootReport in the Java 8 build
+ - if [[ "$JAVAC_VERSION" = javac\ 1.8.* ]]; then gradle jacocoRootReport coveralls; fi
diff --git a/build.gradle b/build.gradle
index 92a62e572..9ca176231 100644
--- a/build.gradle
+++ b/build.gradle
@@ -8,9 +8,9 @@ buildscript {
}
dependencies {
classpath 'org.kordamp:markdown-gradle-plugin:1.0.0'
- classpath 'org.kordamp.gradle:clirr-gradle-plugin:0.2.0'
+ classpath 'org.kordamp.gradle:clirr-gradle-plugin:0.2.2'
classpath "org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.3.1"
- classpath 'net.ltgt.gradle:gradle-errorprone-plugin:0.0.9'
+ classpath 'net.ltgt.gradle:gradle-errorprone-plugin:0.0.10'
}
}
apply plugin: 'org.kordamp.gradle.markdown'
@@ -20,6 +20,7 @@ apply from: 'version.gradle'
allprojects {
apply plugin: 'java'
apply plugin: 'eclipse'
+ apply plugin: 'idea'
apply plugin: 'jacoco'
apply plugin: 'net.ltgt.errorprone'
@@ -266,6 +267,7 @@ subprojects {
checkstyle {
configFile = new File(rootConfigDir, 'checkstyle.xml')
+ toolVersion = '7.7'
}
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
diff --git a/config/checkstyle.xml b/config/checkstyle.xml
index ce2345c20..d5ce5464e 100644
--- a/config/checkstyle.xml
+++ b/config/checkstyle.xml
@@ -117,5 +117,75 @@
, INDEX_OP
"/>
+
+
+
+
+
+
+
+
diff --git a/documentation/extensions/index.md b/documentation/extensions/index.md
index 325fcf30a..05ffa0b5c 100644
--- a/documentation/extensions/index.md
+++ b/documentation/extensions/index.md
@@ -87,6 +87,7 @@ Experimental Smack Extensions and currently supported XEPs of smack-experimental
| [Internet of Things - Control](iot.md) | [XEP-0325](http://xmpp.org/extensions/xep-0325.html) | Describes how to control devices or actuators in an XMPP-based sensor netowrk. |
| [HTTP over XMPP transport](hoxt.md) | [XEP-0332](http://xmpp.org/extensions/xep-0332.html) | Allows to transport HTTP communication over XMPP peer-to-peer networks. |
| Chat Markers | [XEP-0333](http://xmpp.org/extensions/xep-0333.html) | A solution of marking the last received, displayed and acknowledged message in a chat. |
+| Message Processing Hints | [XEP-0334](http://xmpp.org/extensions/xep-0334.html) | Hints to entities routing or receiving a message. |
| JSON Containers | [XEP-0335](http://xmpp.org/extensions/xep-0335.html) | Encapsulation of JSON data within XMPP Stanzas. |
| [Internet of Things - Discovery](iot.md) | [XEP-0347](http://xmpp.org/extensions/xep-0347.html) | Describes how Things can be installed and discovered by their owners. |
| Client State Indication | [XEP-0352](http://xmpp.org/extensions/xep-0352.html) | A way for the client to indicate its active/inactive state. |
diff --git a/smack-bosh/src/main/java/org/jivesoftware/smack/bosh/XMPPBOSHConnection.java b/smack-bosh/src/main/java/org/jivesoftware/smack/bosh/XMPPBOSHConnection.java
index b91bb5a40..32edb865f 100644
--- a/smack-bosh/src/main/java/org/jivesoftware/smack/bosh/XMPPBOSHConnection.java
+++ b/smack-bosh/src/main/java/org/jivesoftware/smack/bosh/XMPPBOSHConnection.java
@@ -325,7 +325,7 @@ public class XMPPBOSHConnection extends AbstractXMPPConnection {
writer = new Writer() {
@Override
public void write(char[] cbuf, int off, int len) {
- /* ignore */}
+ /* ignore */ }
@Override
public void close() {
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java b/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java
index 32b3ada5e..dc467b043 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java
@@ -41,6 +41,7 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import org.jivesoftware.smack.ConnectionConfiguration.SecurityMode;
+import org.jivesoftware.smack.SmackConfiguration.UnknownIqRequestReplyMode;
import org.jivesoftware.smack.SmackException.AlreadyConnectedException;
import org.jivesoftware.smack.SmackException.AlreadyLoggedInException;
import org.jivesoftware.smack.SmackException.NoResponseException;
@@ -626,7 +627,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
hostAddresses = DNSUtil.resolveXMPPServiceDomain(config.getXMPPServiceDomain().toString(), failedAddresses, config.getDnssecMode());
}
// Either the populated host addresses are not empty *or* there must be at least one failed address.
- assert(!hostAddresses.isEmpty() || !failedAddresses.isEmpty());
+ assert (!hostAddresses.isEmpty() || !failedAddresses.isEmpty());
return failedAddresses;
}
@@ -665,7 +666,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
@Override
public void sendStanza(Stanza stanza) throws NotConnectedException, InterruptedException {
Objects.requireNonNull(stanza, "Stanza must not be null");
- assert(stanza instanceof Message || stanza instanceof Presence || stanza instanceof IQ);
+ assert (stanza instanceof Message || stanza instanceof Presence || stanza instanceof IQ);
throwNotConnectedExceptionIfAppropriate();
switch (fromMode) {
@@ -894,7 +895,8 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
continue;
}
}
- }});
+ }
+ });
}
@Override
@@ -991,20 +993,31 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
replyTimeout = timeout;
}
- private static boolean replyToUnknownIqDefault = true;
-
/**
* Set the default value used to determine if new connection will reply to unknown IQ requests. The pre-configured
* default is 'true'.
*
* @param replyToUnkownIqDefault
* @see #setReplyToUnknownIq(boolean)
+ * @deprecated Use {@link SmackConfiguration#setUnknownIqRequestReplyMode(org.jivesoftware.smack.SmackConfiguration.UnknownIqRequestReplyMode)} instead.
*/
+ @Deprecated
+ // TODO Remove in Smack 4.3
public static void setReplyToUnknownIqDefault(boolean replyToUnkownIqDefault) {
- AbstractXMPPConnection.replyToUnknownIqDefault = replyToUnkownIqDefault;
+ SmackConfiguration.UnknownIqRequestReplyMode mode;
+ if (replyToUnkownIqDefault) {
+ mode = SmackConfiguration.UnknownIqRequestReplyMode.replyServiceUnavailable;
+ } else {
+ mode = SmackConfiguration.UnknownIqRequestReplyMode.doNotReply;
+ }
+ SmackConfiguration.setUnknownIqRequestReplyMode(mode);
}
- private boolean replyToUnkownIq = replyToUnknownIqDefault;
+ private SmackConfiguration.UnknownIqRequestReplyMode unknownIqRequestReplyMode = SmackConfiguration.getUnknownIqRequestReplyMode();
+
+ public void setUnknownIqRequestReplyMode(UnknownIqRequestReplyMode unknownIqRequestReplyMode) {
+ this.unknownIqRequestReplyMode = Objects.requireNonNull(unknownIqRequestReplyMode, "Mode must not be null");
+ }
/**
* Set if Smack will automatically send
@@ -1012,9 +1025,18 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
* registered {@link IQRequestHandler} is received.
*
* @param replyToUnknownIq
+ * @deprecated use {@link #setUnknownIqRequestReplyMode(UnknownIqRequestReplyMode)} instead.
*/
+ @Deprecated
+ // TODO Remove in Smack 4.3
public void setReplyToUnknownIq(boolean replyToUnknownIq) {
- this.replyToUnkownIq = replyToUnknownIq;
+ SmackConfiguration.UnknownIqRequestReplyMode mode;
+ if (replyToUnknownIq) {
+ mode = SmackConfiguration.UnknownIqRequestReplyMode.replyServiceUnavailable;
+ } else {
+ mode = SmackConfiguration.UnknownIqRequestReplyMode.doNotReply;
+ }
+ unknownIqRequestReplyMode = mode;
}
protected void parseAndProcessStanza(XmlPullParser parser) throws Exception {
@@ -1048,7 +1070,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
* @throws InterruptedException
*/
protected void processStanza(final Stanza stanza) throws InterruptedException {
- assert(stanza != null);
+ assert (stanza != null);
lastStanzaReceived = System.currentTimeMillis();
// Deliver the incoming packet to listeners.
executorService.executeBlocking(new Runnable() {
@@ -1089,13 +1111,24 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
throw new IllegalStateException("Should only encounter IQ type 'get' or 'set'");
}
if (iqRequestHandler == null) {
- if (!replyToUnkownIq) {
+ XMPPError.Condition replyCondition;
+ switch (unknownIqRequestReplyMode) {
+ case doNotReply:
return;
+ case replyFeatureNotImplemented:
+ replyCondition = XMPPError.Condition.feature_not_implemented;
+ break;
+ case replyServiceUnavailable:
+ replyCondition = XMPPError.Condition.service_unavailable;
+ break;
+ default:
+ throw new AssertionError();
}
+
// If the IQ stanza is of type "get" or "set" with no registered IQ request handler, then answer an
// IQ of type 'error' with condition 'service-unavailable'.
ErrorIQ errorIQ = IQ.createErrorResponse(iq, XMPPError.getBuilder((
- XMPPError.Condition.service_unavailable)));
+ replyCondition)));
try {
sendStanza(errorIQ);
}
@@ -1170,7 +1203,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
}
// Loop through all collectors and notify the appropriate ones.
- for (StanzaCollector collector: collectors) {
+ for (StanzaCollector collector : collectors) {
collector.processStanza(packet);
}
@@ -1192,7 +1225,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
for (StanzaListener listener : listenersToNotify) {
try {
listener.processStanza(packet);
- } catch(NotConnectedException e) {
+ } catch (NotConnectedException e) {
LOGGER.log(Level.WARNING, "Got not connected exception, aborting", e);
break;
} catch (Exception e) {
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/ConnectionConfiguration.java b/smack-core/src/main/java/org/jivesoftware/smack/ConnectionConfiguration.java
index 55f76798a..ff35a6968 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/ConnectionConfiguration.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/ConnectionConfiguration.java
@@ -162,7 +162,7 @@ public abstract class ConnectionConfiguration {
enabledSaslMechanisms = builder.enabledSaslMechanisms;
// If the enabledSaslmechanisms are set, then they must not be empty
- assert(enabledSaslMechanisms != null ? !enabledSaslMechanisms.isEmpty() : true);
+ assert (enabledSaslMechanisms != null ? !enabledSaslMechanisms.isEmpty() : true);
if (dnssecMode != DnssecMode.disabled && customSSLContext != null) {
throw new IllegalStateException("You can not use a custom SSL context with DNSSEC enabled");
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/SASLAuthentication.java b/smack-core/src/main/java/org/jivesoftware/smack/SASLAuthentication.java
index 2a0f76119..137e07110 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/SASLAuthentication.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/SASLAuthentication.java
@@ -132,13 +132,13 @@ public final class SASLAuthentication {
}
public static boolean blacklistSASLMechanism(String mechansim) {
- synchronized(BLACKLISTED_MECHANISMS) {
+ synchronized (BLACKLISTED_MECHANISMS) {
return BLACKLISTED_MECHANISMS.add(mechansim);
}
}
public static boolean unBlacklistSASLMechanism(String mechanism) {
- synchronized(BLACKLISTED_MECHANISMS) {
+ synchronized (BLACKLISTED_MECHANISMS) {
return BLACKLISTED_MECHANISMS.remove(mechanism);
}
}
@@ -209,7 +209,7 @@ public final class SASLAuthentication {
}
}
- if (saslException != null){
+ if (saslException != null) {
if (saslException instanceof SmackException) {
throw (SmackException) saslException;
} else if (saslException instanceof SASLErrorException) {
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/SmackConfiguration.java b/smack-core/src/main/java/org/jivesoftware/smack/SmackConfiguration.java
index 2e6770c7a..245e8f0e9 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/SmackConfiguration.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/SmackConfiguration.java
@@ -34,6 +34,7 @@ import org.jivesoftware.smack.debugger.SmackDebugger;
import org.jivesoftware.smack.debugger.SmackDebuggerFactory;
import org.jivesoftware.smack.parsing.ExceptionThrowingCallback;
import org.jivesoftware.smack.parsing.ParsingExceptionCallback;
+import org.jivesoftware.smack.util.Objects;
/**
* Represents the configuration of Smack. The configuration is used for:
@@ -173,7 +174,7 @@ public final class SmackConfiguration {
* @param mech the SASL mechanism to be added
*/
public static void addSaslMech(String mech) {
- if(!defaultMechs.contains(mech)) {
+ if (!defaultMechs.contains(mech)) {
defaultMechs.add(mech);
}
}
@@ -184,7 +185,7 @@ public final class SmackConfiguration {
* @param mechs the Collection of SASL mechanisms to be added
*/
public static void addSaslMechs(Collection mechs) {
- for(String mech : mechs) {
+ for (String mech : mechs) {
addSaslMech(mech);
}
}
@@ -370,4 +371,20 @@ public final class SmackConfiguration {
return defaultHostnameVerififer;
}
+ enum UnknownIqRequestReplyMode {
+ doNotReply,
+ replyFeatureNotImplemented,
+ replyServiceUnavailable,
+ }
+
+ // TODO Change to replyFeatureNotImplemented in Smack 4.3
+ private static UnknownIqRequestReplyMode unknownIqRequestReplyMode = UnknownIqRequestReplyMode.replyServiceUnavailable;
+
+ public static UnknownIqRequestReplyMode getUnknownIqRequestReplyMode() {
+ return unknownIqRequestReplyMode;
+ }
+
+ public static void setUnknownIqRequestReplyMode(UnknownIqRequestReplyMode unknownIqRequestReplyMode) {
+ SmackConfiguration.unknownIqRequestReplyMode = Objects.requireNonNull(unknownIqRequestReplyMode, "Must set mode");
+ }
}
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/SmackFuture.java b/smack-core/src/main/java/org/jivesoftware/smack/SmackFuture.java
new file mode 100644
index 000000000..36dbda2cb
--- /dev/null
+++ b/smack-core/src/main/java/org/jivesoftware/smack/SmackFuture.java
@@ -0,0 +1,170 @@
+/**
+ *
+ * Copyright 2017 Florian Schmaus
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jivesoftware.smack;
+
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+import org.jivesoftware.smack.SmackException.NotConnectedException;
+import org.jivesoftware.smack.packet.Stanza;
+
+public abstract class SmackFuture implements Future {
+
+ private boolean cancelled;
+
+ private V result;
+
+ protected Exception exception;
+
+ private SuccessCallback successCallback;
+
+ private ExceptionCallback exceptionCallback;
+
+ @Override
+ public synchronized final boolean cancel(boolean mayInterruptIfRunning) {
+ if (isDone()) {
+ return false;
+ }
+
+ cancelled = true;
+ return true;
+ }
+
+ @Override
+ public synchronized final boolean isCancelled() {
+ return cancelled;
+ }
+
+ @Override
+ public synchronized final boolean isDone() {
+ return result != null;
+ }
+
+ public void onSuccessOrError(SuccessCallback successCallback, ExceptionCallback exceptionCallback) {
+ this.successCallback = successCallback;
+ this.exceptionCallback = exceptionCallback;
+
+ maybeInvokeCallbacks();
+ }
+
+ public void onSuccess(SuccessCallback successCallback) {
+ onSuccessOrError(successCallback, null);
+ }
+
+ public void onError(ExceptionCallback exceptionCallback) {
+ onSuccessOrError(null, exceptionCallback);
+ }
+
+ private final V getResultOrThrow() throws ExecutionException {
+ assert (result != null || exception != null);
+ if (result != null) {
+ return result;
+ }
+
+ throw new ExecutionException(exception);
+ }
+
+ @Override
+ public synchronized final V get() throws InterruptedException, ExecutionException {
+ while (result == null && exception == null) {
+ wait();
+ }
+
+ return getResultOrThrow();
+ }
+
+ @Override
+ public synchronized final V get(long timeout, TimeUnit unit)
+ throws InterruptedException, ExecutionException, TimeoutException {
+ final long deadline = System.currentTimeMillis() + unit.toMillis(timeout);
+ while (result != null && exception != null) {
+ final long waitTimeRemaining = deadline - System.currentTimeMillis();
+ if (waitTimeRemaining > 0) {
+ wait(waitTimeRemaining);
+ }
+ }
+
+ if (result == null || exception == null) {
+ throw new TimeoutException();
+ }
+
+ return getResultOrThrow();
+ }
+
+ protected final synchronized void maybeInvokeCallbacks() {
+ if (result != null && successCallback != null) {
+ successCallback.onSuccess(result);
+ } else if (exception != null && exceptionCallback != null) {
+ exceptionCallback.processException(exception);
+ }
+ }
+
+ /**
+ * This method checks if the given exception is not fatal. If this method returns false
, then
+ * the future will automatically set the given exception as failure reason and notify potential waiting threads.
+ *
+ * @param exception the exception to check.
+ * @return true
if the exception is not fatal, false
otherwise.
+ */
+ protected abstract boolean isNonFatalException(Exception exception);
+
+ protected abstract void handleStanza(Stanza stanza) throws NotConnectedException, InterruptedException;
+
+ protected final void setResult(V result) {
+ assert (Thread.holdsLock(this));
+
+ this.result = result;
+ this.notifyAll();
+
+ maybeInvokeCallbacks();
+ }
+
+ public static abstract class InternalSmackFuture extends SmackFuture implements StanzaListener, ExceptionCallback {
+
+ @Override
+ public synchronized final void processException(Exception exception) {
+ if (!isNonFatalException(exception)) {
+ this.exception = exception;
+ this.notifyAll();
+
+ maybeInvokeCallbacks();
+ }
+ }
+
+ /**
+ * Wrapper method for {@link #handleStanza(Stanza)}. Note that this method is synchronized
.
+ */
+ @Override
+ public synchronized final void processStanza(Stanza stanza) throws NotConnectedException, InterruptedException {
+ handleStanza(stanza);
+ }
+ }
+
+ /**
+ * A simple version of InternalSmackFuture which implements {@link #isNonFatalException(Exception)} as always returning false
method.
+ *
+ * @param
+ */
+ public static abstract class SimpleInternalSmackFuture extends InternalSmackFuture {
+ @Override
+ protected boolean isNonFatalException(Exception exception) {
+ return false;
+ }
+ }
+}
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/SmackInitialization.java b/smack-core/src/main/java/org/jivesoftware/smack/SmackInitialization.java
index 7bdb8e18a..d7ac9410a 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/SmackInitialization.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/SmackInitialization.java
@@ -68,7 +68,7 @@ public final class SmackInitialization {
} catch (IOException e) {
LOGGER.log(Level.WARNING, "IOException closing stream", e);
}
- } catch(Exception e) {
+ } catch (Exception e) {
LOGGER.log(Level.SEVERE, "Could not determine Smack version", e);
smackVersion = "unkown";
}
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/SuccessCallback.java b/smack-core/src/main/java/org/jivesoftware/smack/SuccessCallback.java
new file mode 100644
index 000000000..49106a9f1
--- /dev/null
+++ b/smack-core/src/main/java/org/jivesoftware/smack/SuccessCallback.java
@@ -0,0 +1,23 @@
+/**
+ *
+ * Copyright 2017 Florian Schmaus
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jivesoftware.smack;
+
+public interface SuccessCallback {
+
+ public void onSuccess(T result);
+
+}
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/SynchronizationPoint.java b/smack-core/src/main/java/org/jivesoftware/smack/SynchronizationPoint.java
index bb1984a1f..8906fc65e 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/SynchronizationPoint.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/SynchronizationPoint.java
@@ -79,7 +79,7 @@ public class SynchronizationPoint {
if (request instanceof Stanza) {
connection.sendStanza((Stanza) request);
}
- else if (request instanceof Nonza){
+ else if (request instanceof Nonza) {
connection.sendNonza((Nonza) request);
} else {
throw new IllegalStateException("Unsupported element type");
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/XMPPConnection.java b/smack-core/src/main/java/org/jivesoftware/smack/XMPPConnection.java
index b8b8582bf..b22d004aa 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/XMPPConnection.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/XMPPConnection.java
@@ -413,6 +413,7 @@ public interface XMPPConnection {
* @deprecated use {@link #getReplyTimeout()} instead.
*/
@Deprecated
+ // TODO Remove in Smack 4.3
public long getPacketReplyTimeout();
/**
@@ -423,6 +424,7 @@ public interface XMPPConnection {
* @deprecated use {@link #setReplyTimeout(long)} instead.
*/
@Deprecated
+ // TODO Remove in Smack 4.3
public void setPacketReplyTimeout(long timeout);
/**
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/filter/AbstractJidTypeFilter.java b/smack-core/src/main/java/org/jivesoftware/smack/filter/AbstractJidTypeFilter.java
index e091d6786..502c2951e 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/filter/AbstractJidTypeFilter.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/filter/AbstractJidTypeFilter.java
@@ -39,7 +39,7 @@ public abstract class AbstractJidTypeFilter implements StanzaFilter {
@Override
public final boolean accept(Stanza stanza) {
- final Jid jid = stanza.getFrom();
+ final Jid jid = getJidToInspect(stanza);
if (jid == null) {
return false;
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/filter/AbstractListFilter.java b/smack-core/src/main/java/org/jivesoftware/smack/filter/AbstractListFilter.java
index 708d7b52f..d06ddad47 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/filter/AbstractListFilter.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/filter/AbstractListFilter.java
@@ -45,7 +45,7 @@ public abstract class AbstractListFilter implements StanzaFilter {
*/
protected AbstractListFilter(StanzaFilter... filters) {
Objects.requireNonNull(filters, "Parameter must not be null.");
- for(StanzaFilter filter : filters) {
+ for (StanzaFilter filter : filters) {
Objects.requireNonNull(filter, "Parameter must not be null.");
}
this.filters = new ArrayList(Arrays.asList(filters));
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/filter/MessageWithThreadFilter.java b/smack-core/src/main/java/org/jivesoftware/smack/filter/MessageWithThreadFilter.java
new file mode 100644
index 000000000..81a5bc8ea
--- /dev/null
+++ b/smack-core/src/main/java/org/jivesoftware/smack/filter/MessageWithThreadFilter.java
@@ -0,0 +1,43 @@
+/**
+ *
+ * Copyright 2017 Florian Schmaus
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jivesoftware.smack.filter;
+
+import org.jivesoftware.smack.packet.Message;
+import org.jivesoftware.smack.util.StringUtils;
+
+/**
+ * Filters message stanzas which have at least one body.
+ */
+public final class MessageWithThreadFilter extends FlexibleStanzaTypeFilter {
+
+ public static final StanzaFilter INSTANCE = new MessageWithThreadFilter();
+
+ private MessageWithThreadFilter() {
+ super(Message.class);
+ }
+
+ @Override
+ protected boolean acceptSpecific(Message message) {
+ return StringUtils.isNotEmpty(message.getThread());
+ }
+
+ @Override
+ public String toString() {
+ return getClass().getSimpleName();
+ }
+}
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/packet/AbstractError.java b/smack-core/src/main/java/org/jivesoftware/smack/packet/AbstractError.java
index 26e3daf69..d04c41ad3 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/packet/AbstractError.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/packet/AbstractError.java
@@ -67,7 +67,10 @@ public class AbstractError {
String defaultLocale = Locale.getDefault().getLanguage();
String descriptiveText = getDescriptiveText(defaultLocale);
if (descriptiveText == null) {
- descriptiveText = getDescriptiveText("");
+ descriptiveText = getDescriptiveText("en");
+ if (descriptiveText == null) {
+ descriptiveText = getDescriptiveText("");
+ }
}
return descriptiveText;
}
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/packet/Message.java b/smack-core/src/main/java/org/jivesoftware/smack/packet/Message.java
index d2f096de6..11bb224ef 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/packet/Message.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/packet/Message.java
@@ -488,7 +488,7 @@ public final class Message extends Stanza implements TypedCloneable {
// Add the subject in other languages
for (Subject subject : getSubjects()) {
// Skip the default language
- if(subject.equals(defaultSubject))
+ if (subject.equals(defaultSubject))
continue;
buf.append(subject.toXML());
}
@@ -500,7 +500,7 @@ public final class Message extends Stanza implements TypedCloneable {
// Add the bodies in other languages
for (Body body : getBodies()) {
// Skip the default language
- if(body.equals(defaultBody))
+ if (body.equals(defaultBody))
continue;
buf.append(body.toXML());
}
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/packet/StandardExtensionElement.java b/smack-core/src/main/java/org/jivesoftware/smack/packet/StandardExtensionElement.java
index a7d98a3e7..35d904f20 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/packet/StandardExtensionElement.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/packet/StandardExtensionElement.java
@@ -120,7 +120,7 @@ public final class StandardExtensionElement implements ExtensionElement {
}
public List getElements() {
- if (elements == null){
+ if (elements == null) {
return Collections.emptyList();
}
return elements.values();
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/provider/Provider.java b/smack-core/src/main/java/org/jivesoftware/smack/provider/Provider.java
index 7b4a659eb..b9d64e7aa 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/provider/Provider.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/provider/Provider.java
@@ -23,7 +23,7 @@ import org.xmlpull.v1.XmlPullParser;
public abstract class Provider {
- public final E parse(XmlPullParser parser) throws Exception{
+ public final E parse(XmlPullParser parser) throws Exception {
// XPP3 calling convention assert: Parser should be at start tag
ParserUtils.assertAtStartTag(parser);
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/provider/ProviderFileLoader.java b/smack-core/src/main/java/org/jivesoftware/smack/provider/ProviderFileLoader.java
index bee798fb0..4fa884d39 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/provider/ProviderFileLoader.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/provider/ProviderFileLoader.java
@@ -135,7 +135,7 @@ public class ProviderFileLoader implements ProviderLoader {
}
while (eventType != XmlPullParser.END_DOCUMENT);
}
- catch (Exception e){
+ catch (Exception e) {
LOGGER.log(Level.SEVERE, "Unknown error occurred while parsing provider file", e);
exceptions.add(e);
}
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/proxy/ProxyException.java b/smack-core/src/main/java/org/jivesoftware/smack/proxy/ProxyException.java
index ccf0f9b25..551b06876 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/proxy/ProxyException.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/proxy/ProxyException.java
@@ -31,7 +31,7 @@ public class ProxyException extends IOException {
public ProxyException(ProxyInfo.ProxyType type, String ex)
{
- super("Proxy Exception " + type.toString() + " : "+ex);
+ super("Proxy Exception " + type.toString() + " : " + ex);
}
public ProxyException(ProxyInfo.ProxyType type)
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/proxy/Socks4ProxySocketConnection.java b/smack-core/src/main/java/org/jivesoftware/smack/proxy/Socks4ProxySocketConnection.java
index 65a54059a..b416319d0 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/proxy/Socks4ProxySocketConnection.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/proxy/Socks4ProxySocketConnection.java
@@ -50,12 +50,12 @@ public class Socks4ProxySocketConnection implements ProxySocketConnection {
try
{
socket.connect(new InetSocketAddress(proxy_host, proxy_port), timeout);
- in=socket.getInputStream();
- out=socket.getOutputStream();
+ in = socket.getInputStream();
+ out = socket.getOutputStream();
socket.setTcpNoDelay(true);
- byte[] buf=new byte[1024];
- int index=0;
+ byte[] buf = new byte[1024];
+ int index = 0;
/*
1) CONNECT
@@ -75,27 +75,27 @@ public class Socks4ProxySocketConnection implements ProxySocketConnection {
of all zero bits.
*/
- index=0;
- buf[index++]=4;
- buf[index++]=1;
+ index = 0;
+ buf[index++] = 4;
+ buf[index++] = 1;
- buf[index++]=(byte)(port>>>8);
- buf[index++]=(byte)(port&0xff);
+ buf[index++] = (byte) (port >>> 8);
+ buf[index++] = (byte) (port & 0xff);
InetAddress inetAddress = InetAddress.getByName(proxy_host);
byte[] byteAddress = inetAddress.getAddress();
for (int i = 0; i < byteAddress.length; i++)
{
- buf[index++]=byteAddress[i];
+ buf[index++] = byteAddress[i];
}
- if(user!=null)
+ if (user != null)
{
byte[] userBytes = user.getBytes(StringUtils.UTF8);
System.arraycopy(userBytes, 0, buf, index, user.length());
- index+=user.length();
+ index += user.length();
}
- buf[index++]=0;
+ buf[index++] = 0;
out.write(buf, 0, index);
/*
@@ -125,49 +125,49 @@ public class Socks4ProxySocketConnection implements ProxySocketConnection {
The remaining fields are ignored.
*/
- int len=6;
- int s=0;
- while(s>>8);
- buf[index++]=(byte)(port&0xff);
+ index += len;
+ buf[index++] = (byte) (port >>> 8);
+ buf[index++] = (byte) (port & 0xff);
out.write(buf, 0, index);
@@ -263,20 +263,20 @@ public class Socks5ProxySocketConnection implements ProxySocketConnection {
//in.read(buf, 0, 4);
fill(in, buf, 4);
- if(buf[1]!=0)
+ if (buf[1] != 0)
{
try
{
socket.close();
}
- catch(Exception eee)
+ catch (Exception eee)
{
}
throw new ProxyException(ProxyInfo.ProxyType.SOCKS5,
- "server returns "+buf[1]);
+ "server returns " + buf[1]);
}
- switch(buf[3]&0xff)
+ switch (buf[3] & 0xff)
{
case 1:
//in.read(buf, 0, 6);
@@ -286,7 +286,7 @@ public class Socks5ProxySocketConnection implements ProxySocketConnection {
//in.read(buf, 0, 1);
fill(in, buf, 1);
//in.read(buf, 0, buf[0]+2);
- fill(in, buf, (buf[0]&0xff)+2);
+ fill(in, buf, (buf[0] & 0xff) + 2);
break;
case 4:
//in.read(buf, 0, 18);
@@ -295,17 +295,17 @@ public class Socks5ProxySocketConnection implements ProxySocketConnection {
default:
}
}
- catch(RuntimeException e)
+ catch (RuntimeException e)
{
throw e;
}
- catch(Exception e)
+ catch (Exception e)
{
try
{
socket.close();
}
- catch(Exception eee)
+ catch (Exception eee)
{
}
// TODO convert to IOException(e) when minimum Android API level is 9 or higher
@@ -316,16 +316,16 @@ public class Socks5ProxySocketConnection implements ProxySocketConnection {
private static void fill(InputStream in, byte[] buf, int len)
throws IOException
{
- int s=0;
- while(s {
this.password = password;
this.authorizationId = authzid;
this.sslSession = sslSession;
- assert(authorizationId == null || authzidSupported());
+ assert (authorizationId == null || authzidSupported());
authenticateInternal();
authenticate();
}
@@ -194,7 +194,7 @@ public abstract class SASLMechanism implements Comparable {
this.serviceName = serviceName;
this.authorizationId = authzid;
this.sslSession = sslSession;
- assert(authorizationId == null || authzidSupported());
+ assert (authorizationId == null || authzidSupported());
authenticateInternal(cbh);
authenticate();
}
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/sasl/core/ScramMechanism.java b/smack-core/src/main/java/org/jivesoftware/smack/sasl/core/ScramMechanism.java
index 4209083c1..8ce0e8b36 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/sasl/core/ScramMechanism.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/sasl/core/ScramMechanism.java
@@ -232,7 +232,7 @@ public abstract class ScramMechanism extends SASLMechanism {
}
String cbName = getChannelBindingName();
- assert(StringUtils.isNotEmpty(cbName));
+ assert (StringUtils.isNotEmpty(cbName));
return cbName + ',' + authzidPortion + ",";
}
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/EventManger.java b/smack-core/src/main/java/org/jivesoftware/smack/util/EventManger.java
index 69ca3d6eb..c778fcdf3 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/util/EventManger.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/util/EventManger.java
@@ -81,7 +81,7 @@ public class EventManger {
return false;
}
reference.eventResult = eventResult;
- synchronized(reference) {
+ synchronized (reference) {
reference.notifyAll();
}
return true;
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/LazyStringBuilder.java b/smack-core/src/main/java/org/jivesoftware/smack/util/LazyStringBuilder.java
index 638ada32d..6baf74625 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/util/LazyStringBuilder.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/util/LazyStringBuilder.java
@@ -1,6 +1,6 @@
/**
*
- * Copyright 2014 Florian Schmaus
+ * Copyright 2014-2017 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,9 +19,13 @@ package org.jivesoftware.smack.util;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
public class LazyStringBuilder implements Appendable, CharSequence {
+ private static final Logger LOGGER = Logger.getLogger(LazyStringBuilder.class.getName());
+
private final List list;
private String cache;
@@ -69,8 +73,15 @@ public class LazyStringBuilder implements Appendable, CharSequence {
return cache.length();
}
int length = 0;
- for (CharSequence csq : list) {
- length += csq.length();
+ try {
+ for (CharSequence csq : list) {
+ length += csq.length();
+ }
+ }
+ catch (NullPointerException npe) {
+ StringBuilder sb = safeToStringBuilder();
+ LOGGER.log(Level.SEVERE, "The following LazyStringBuilder threw a NullPointerException: " + sb, npe);
+ throw npe;
}
return length;
}
@@ -107,6 +118,14 @@ public class LazyStringBuilder implements Appendable, CharSequence {
return cache;
}
+ public StringBuilder safeToStringBuilder() {
+ StringBuilder sb = new StringBuilder();
+ for (CharSequence csq : list) {
+ sb.append(csq);
+ }
+ return sb;
+ }
+
/**
* Get the List of CharSequences representation of this instance. The list is unmodifiable. If
* the resulting String was already cached, a list with a single String entry will be returned.
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/MultiMap.java b/smack-core/src/main/java/org/jivesoftware/smack/util/MultiMap.java
index 479b8c395..1a6401e05 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/util/MultiMap.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/util/MultiMap.java
@@ -143,7 +143,7 @@ public class MultiMap {
if (res == null) {
return null;
}
- assert(!res.isEmpty());
+ assert (!res.isEmpty());
return res.iterator().next();
}
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/PacketParserUtils.java b/smack-core/src/main/java/org/jivesoftware/smack/util/PacketParserUtils.java
index 4c9ce0699..498344bb8 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/util/PacketParserUtils.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/util/PacketParserUtils.java
@@ -214,7 +214,7 @@ public class PacketParserUtils {
public static Message parseMessage(XmlPullParser parser)
throws Exception {
ParserUtils.assertAtStartTag(parser);
- assert(parser.getName().equals(Message.ELEMENT));
+ assert (parser.getName().equals(Message.ELEMENT));
final int initialDepth = parser.getDepth();
Message message = new Message();
@@ -247,7 +247,7 @@ public class PacketParserUtils {
case XmlPullParser.START_TAG:
String elementName = parser.getName();
String namespace = parser.getNamespace();
- switch(elementName) {
+ switch (elementName) {
case "subject":
String xmlLangSubject = getLanguageAttribute(parser);
if (xmlLangSubject == null) {
@@ -385,7 +385,7 @@ public class PacketParserUtils {
*/
public static CharSequence parseContent(XmlPullParser parser)
throws XmlPullParserException, IOException {
- assert(parser.getEventType() == XmlPullParser.START_TAG);
+ assert (parser.getEventType() == XmlPullParser.START_TAG);
if (parser.isEmptyElementTag()) {
return "";
}
@@ -546,7 +546,7 @@ public class PacketParserUtils {
case XmlPullParser.START_TAG:
String elementName = parser.getName();
String namespace = parser.getNamespace();
- switch(elementName) {
+ switch (elementName) {
case "status":
presence.setStatus(parser.nextText());
break;
@@ -620,7 +620,7 @@ public class PacketParserUtils {
case XmlPullParser.START_TAG:
String elementName = parser.getName();
String namespace = parser.getNamespace();
- switch(elementName) {
+ switch (elementName) {
case "error":
error = PacketParserUtils.parseError(parser);
break;
@@ -775,7 +775,7 @@ public class PacketParserUtils {
descriptiveTexts = parseDescriptiveTexts(parser, descriptiveTexts);
}
else {
- assert(condition == null);
+ assert (condition == null);
condition = parser.getName();
}
break;
@@ -945,7 +945,7 @@ public class PacketParserUtils {
}
}
}
- assert(parser.getEventType() == XmlPullParser.END_TAG);
+ assert (parser.getEventType() == XmlPullParser.END_TAG);
return new StartTls(required);
}
@@ -954,7 +954,7 @@ public class PacketParserUtils {
final int initialDepth = parser.getDepth();
boolean optional = false;
if (!parser.isEmptyElementTag()) {
- outerloop: while(true) {
+ outerloop: while (true) {
int event = parser.next();
switch (event) {
case XmlPullParser.START_TAG:
@@ -1022,7 +1022,7 @@ public class PacketParserUtils {
}
public static void addExtensionElement(Stanza packet, XmlPullParser parser, String elementName,
- String namespace) throws Exception{
+ String namespace) throws Exception {
ExtensionElement packetExtension = parseExtensionElement(elementName, namespace, parser);
packet.addExtension(packetExtension);
}
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/ParserUtils.java b/smack-core/src/main/java/org/jivesoftware/smack/util/ParserUtils.java
index 9a5b68153..3badf6a02 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/util/ParserUtils.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/util/ParserUtils.java
@@ -43,7 +43,7 @@ public class ParserUtils {
public static final String JID = "jid";
public static void assertAtStartTag(XmlPullParser parser) throws XmlPullParserException {
- assert(parser.getEventType() == XmlPullParser.START_TAG);
+ assert (parser.getEventType() == XmlPullParser.START_TAG);
}
public static void assertAtStartTag(XmlPullParser parser, String name) throws XmlPullParserException {
@@ -52,7 +52,7 @@ public class ParserUtils {
}
public static void assertAtEndTag(XmlPullParser parser) throws XmlPullParserException {
- assert(parser.getEventType() == XmlPullParser.END_TAG);
+ assert (parser.getEventType() == XmlPullParser.END_TAG);
}
public static void forwardToEndTagOfDepth(XmlPullParser parser, int depth)
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/StringUtils.java b/smack-core/src/main/java/org/jivesoftware/smack/util/StringUtils.java
index 94e528099..c2bb9210a 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/util/StringUtils.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/util/StringUtils.java
@@ -121,7 +121,7 @@ public class StringUtils {
return null;
}
final int len = input.length();
- final StringBuilder out = new StringBuilder((int)(len*1.3));
+ final StringBuilder out = new StringBuilder((int) (len * 1.3));
CharSequence toAppend;
char ch;
int last = 0;
@@ -153,7 +153,7 @@ public class StringUtils {
break;
case forAttribute:
// No need to escape '>' for attributes.
- switch(ch) {
+ switch (ch) {
case '<':
toAppend = LT_ENCODE;
break;
@@ -172,7 +172,7 @@ public class StringUtils {
break;
case forAttributeApos:
// No need to escape '>' and '"' for attributes using '\'' as quote.
- switch(ch) {
+ switch (ch) {
case '<':
toAppend = LT_ENCODE;
break;
@@ -188,7 +188,7 @@ public class StringUtils {
break;
case forText:
// No need to escape '"', '\'', and '>' for text.
- switch(ch) {
+ switch (ch) {
case '<':
toAppend = LT_ENCODE;
break;
@@ -307,8 +307,8 @@ public class StringUtils {
final Random random = randGen.get();
// Create a char buffer to put random letters and numbers in.
- char [] randBuffer = new char[length];
- for (int i=0; i future = new SimpleInternalSmackFuture() {
+ @Override
+ protected void handleStanza(Stanza stanza) throws NotConnectedException, InterruptedException {
+ setResult(true);
+ }
+ };
+
+ future.processStanza(null);
+
+ assertTrue(future.get());
+ }
+
+ @Test(expected = TimeoutException.class)
+ public void simpleSmackFutureTimeoutTest() throws InterruptedException, ExecutionException, TimeoutException {
+ InternalSmackFuture future = new SimpleInternalSmackFuture() {
+ @Override
+ protected void handleStanza(Stanza stanza) throws NotConnectedException, InterruptedException {
+ }
+ };
+
+ future.get(5, TimeUnit.SECONDS);
+ }
+}
diff --git a/smack-core/src/test/java/org/jivesoftware/smack/StanzaCollectorTest.java b/smack-core/src/test/java/org/jivesoftware/smack/StanzaCollectorTest.java
index 4120f4529..5bd654721 100644
--- a/smack-core/src/test/java/org/jivesoftware/smack/StanzaCollectorTest.java
+++ b/smack-core/src/test/java/org/jivesoftware/smack/StanzaCollectorTest.java
@@ -31,7 +31,7 @@ public class StanzaCollectorTest
{
TestStanzaCollector collector = new TestStanzaCollector(null, new OKEverything(), 5);
- for (int i=0; i<6; i++)
+ for (int i = 0; i < 6; i++)
{
Stanza testPacket = new TestPacket(i);
collector.processStanza(testPacket);
@@ -45,7 +45,7 @@ public class StanzaCollectorTest
assertEquals("5", collector.pollResult().getStanzaId());
assertNull(collector.pollResult());
- for (int i=10; i<15; i++)
+ for (int i = 10; i < 15; i++)
{
Stanza testPacket = new TestPacket(i);
collector.processStanza(testPacket);
@@ -156,7 +156,7 @@ public class StanzaCollectorTest
consumer2.start();
consumer3.start();
- for(int i=0; i responsePairs = new HashMap();
for (String part : responseParts) {
- String[] keyValue = part.split("=");
- assertTrue(keyValue.length == 2);
+ String[] keyValue = part.split("=", 2);
String key = keyValue[0];
String value = keyValue[1].replace("\"", "");
responsePairs.put(key, value);
@@ -59,7 +58,7 @@ public class DigestMd5SaslTest extends AbstractSaslTest {
if (useAuthzid) {
assertMapValue("authzid", "shazbat@xmpp.org", responsePairs);
} else {
- assert(!responsePairs.containsKey("authzid"));
+ assertTrue (!responsePairs.containsKey("authzid"));
}
assertMapValue("username", "florian", responsePairs);
assertMapValue("realm", "xmpp.org", responsePairs);
diff --git a/smack-core/src/test/java/org/jivesoftware/smack/util/PacketParserUtilsTest.java b/smack-core/src/test/java/org/jivesoftware/smack/util/PacketParserUtilsTest.java
index b988a3e3a..1494f220a 100644
--- a/smack-core/src/test/java/org/jivesoftware/smack/util/PacketParserUtilsTest.java
+++ b/smack-core/src/test/java/org/jivesoftware/smack/util/PacketParserUtilsTest.java
@@ -664,7 +664,7 @@ public class PacketParserUtilsTest {
*
* @throws Exception
*/
- @Test(expected=XmlPullParserException.class)
+ @Test(expected = XmlPullParserException.class)
public void invalidMessageBodyContainingTagTest() throws Exception {
String control = XMLBuilder.create("message")
.a("from", "romeo@montague.lit/orchard")
@@ -701,7 +701,7 @@ public class PacketParserUtilsTest {
try {
PacketParserUtils.parseMessage(PacketParserUtils.getParserFor(invalidControl));
fail("Exception should be thrown");
- } catch(XmlPullParserException e) {
+ } catch (XmlPullParserException e) {
assertTrue(e.getMessage().contains("end tag name "));
}
@@ -710,7 +710,7 @@ public class PacketParserUtilsTest {
try {
PacketParserUtils.parseMessage(PacketParserUtils.getParserFor(invalidControl));
fail("Exception should be thrown");
- } catch(XmlPullParserException e) {
+ } catch (XmlPullParserException e) {
assertTrue(e.getMessage().contains("end tag name