1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-12-23 04:57:58 +01:00

Fix initialization order issue with DEBUG_ENABLED

If a user enabled Smack debug via the property 'smack.debugEnabled', a
ConnectionConfiguration could be created where debuggerEnabled is
'false', because Smack is not yet initialized.

Also make sure that if the property is not set, it won't overwrite
DEBUG_ENABLED = true.

Thanks to William Murphy for providing a detailed issue description and
supposing a fix.
This commit is contained in:
Florian Schmaus 2014-10-19 21:48:17 +02:00
parent 3733a6aaa5
commit dfc4173e5b
2 changed files with 11 additions and 1 deletions

View file

@ -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

View file

@ -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.