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 4f375827d..7e215d9af 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/ConnectionConfiguration.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/ConnectionConfiguration.java @@ -45,6 +45,12 @@ import java.util.List; */ public class ConnectionConfiguration implements Cloneable { + static { + // Ensure that Smack is initialized when ConnectionConfiguration is used, or otherwise e.g. + // SmackConfiguration.DEBUG_ENABLED may not be initialized yet. + SmackConfiguration.getVersion(); + } + /** * Hostname of the XMPP server. Usually servers use the same service name as the name * of the server. However, there are some servers like google where host would be 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 20d04737c..ff59f37e6 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/SmackInitialization.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/SmackInitialization.java @@ -120,7 +120,11 @@ public final class SmackInitialization { // Use try block since we may not have permission to get a system // property (for example, when an applet). try { - SmackConfiguration.DEBUG_ENABLED = Boolean.getBoolean("smack.debugEnabled"); + // Only overwrite DEBUG_ENABLED if it is set via the 'smack.debugEnabled' property. To prevent DEBUG_ENABLED + // = true, which could be set e.g. via a static block from user code, from being overwritten by the property not set + if (Boolean.getBoolean("smack.debugEnabled")) { + SmackConfiguration.DEBUG_ENABLED = true; + } } catch (Exception e) { // Ignore.