mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-12-23 02:58:00 +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:
parent
3733a6aaa5
commit
dfc4173e5b
2 changed files with 11 additions and 1 deletions
|
@ -45,6 +45,12 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
public class ConnectionConfiguration implements Cloneable {
|
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
|
* 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
|
* of the server. However, there are some servers like google where host would be
|
||||||
|
|
|
@ -120,7 +120,11 @@ public final class SmackInitialization {
|
||||||
// Use try block since we may not have permission to get a system
|
// Use try block since we may not have permission to get a system
|
||||||
// property (for example, when an applet).
|
// property (for example, when an applet).
|
||||||
try {
|
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) {
|
catch (Exception e) {
|
||||||
// Ignore.
|
// Ignore.
|
||||||
|
|
Loading…
Reference in a new issue