diff --git a/xmppserver/src/main/java/org/jivesoftware/util/SystemProperty.java b/xmppserver/src/main/java/org/jivesoftware/util/SystemProperty.java index 37b96ece8a..0bd4ee7220 100644 --- a/xmppserver/src/main/java/org/jivesoftware/util/SystemProperty.java +++ b/xmppserver/src/main/java/org/jivesoftware/util/SystemProperty.java @@ -232,6 +232,7 @@ public void xmlPropertyDeleted(final String property, final Map private final Class baseClass; private final Class collectionType; private final boolean sorted; + private volatile ClassLoader classLoader; private SystemProperty(final Builder builder) { // Before we do anything, convert XML based provider setup to Database based @@ -241,6 +242,9 @@ private SystemProperty(final Builder builder) { this.plugin = builder.plugin; this.description = LocaleUtils.getLocalizedPluginString(plugin, "system_property." + key); this.defaultValue = builder.defaultValue; + if (defaultValue instanceof Class) { + this.classLoader = ((Class) defaultValue).getClassLoader(); + } this.minValue = builder.minValue; this.maxValue = builder.maxValue; this.dynamic = builder.dynamic; @@ -302,21 +306,31 @@ private Class getConverterClass() { */ @SuppressWarnings("unchecked") public T getValue() { - final T value = (T) FROM_STRING.get(getConverterClass()).apply(JiveGlobals.getProperty(key), this); - if (value == null || (Collection.class.isAssignableFrom(value.getClass()) && ((Collection) value).isEmpty())) { - return defaultValue; - } - if (minValue != null && ((Comparable) minValue).compareTo(value) > 0) { - LOGGER.warn("Configured value of {} is less than the minimum value of {} for the SystemProperty {} - will use default value of {} instead", - value, minValue, key, defaultValue); - return defaultValue; - } - if (maxValue != null && ((Comparable) maxValue).compareTo(value) < 0) { - LOGGER.warn("Configured value of {} is more than the maximum value of {} for the SystemProperty {} - will use default value of {} instead", - value, maxValue, key, defaultValue); - return defaultValue; + ClassLoader previousClassLoader = Thread.currentThread().getContextClassLoader(); + try { + ClassLoader cl = classLoader; + if (cl != null) { + Thread.currentThread().setContextClassLoader(cl); + } + + final T value = (T) FROM_STRING.get(getConverterClass()).apply(JiveGlobals.getProperty(key), this); + if (value == null || (Collection.class.isAssignableFrom(value.getClass()) && ((Collection) value).isEmpty())) { + return defaultValue; + } + if (minValue != null && ((Comparable) minValue).compareTo(value) > 0) { + LOGGER.warn("Configured value of {} is less than the minimum value of {} for the SystemProperty {} - will use default value of {} instead", + value, minValue, key, defaultValue); + return defaultValue; + } + if (maxValue != null && ((Comparable) maxValue).compareTo(value) < 0) { + LOGGER.warn("Configured value of {} is more than the maximum value of {} for the SystemProperty {} - will use default value of {} instead", + value, maxValue, key, defaultValue); + return defaultValue; + } + return value; + } finally { + Thread.currentThread().setContextClassLoader(previousClassLoader); } - return value; } /** @@ -354,6 +368,10 @@ public String getDefaultDisplayValue() { * @param value the new value for the SystemProperty */ public void setValue(final T value) { + if (value instanceof Class) { + Class clazz = ((Class) value); + this.classLoader = clazz.getClassLoader(); + } JiveGlobals.setProperty(key, TO_STRING.get(getConverterClass()).apply(value, this), isEncrypted()); }