NullpointerException in SmackConfiguration

Hi there,

I am developing a service status indicator using smack for XMPP connectivity. All my standalone tests run fine, but when smack classes are loaded by a the jboss microcontainer classloader I recognize a problem in the static class initialization code of SmackConfiguration.

SmackConfiguration.getClassLoaders() returns an array of classloaders, but does not check, whether the classloader is null or not. It seems the jboss microcontainer uses it’'s own bootstrap classloader, because new SmackConfiguration().getClass().getClassLoader() returns null, when instantiating the class in this container.

The documentation of Class.getClassLoader() explains this behaviour: “Some implementations may use null to represent the bootstrap class loader. This method will return null in such implementations if this class was loaded by the bootstrap class loader.”

A fix should be quite simple. Just check in SmackConfiguration.getClassLoaders(), if the retrieved classloaders exists

Message was edited by: tzwoenn

Why aren’'t you using the presence plugin for that?

Well, the presence plugin is for web based access of user’‘s presence. I want to use XMPP to track the state of some services. Therefore I created some extensions for Log4J and java.util.logging, so logging statements are logged through jabber. In the case of exceptions the state of the service’‘s jabber client should change it’'s presence mode and text to reflect this.

Apart from my visions smack still contain a bug, because the returning classloaders are not tested against null values.

That sounds like it’‘s easy to fix, so you can just fix it yourself and submit a patch (via this forum). I’'ve done this a few times now.

As far as I remember, smack is java 1.3 compliant, is not it? This patch will remove all null from the list, before returning it.

--- SmackConfiguration.old      2006-06-12 18:13:16.000000000 +0200
+++      2006-07-31 19:09:01.000000000 +0200
@@ -25,7 +25,9 @@ import; import;
+import java.util.ArrayList; import java.util.Enumeration;
+import java.util.List; /**
  * Represents the configuration of Smack. The configuration is used for:
@@ -199,9 +201,12 @@
      * @return an array of ClassLoader instances.
     private static ClassLoader[] getClassLoaders() {
-        ClassLoader[] classLoaders = new ClassLoader[2];
-        classLoaders[0] = new SmackConfiguration().getClass().getClassLoader();
-        classLoaders[1] = Thread.currentThread().getContextClassLoader();
-        return classLoaders;
+        List classLoaders = new ArrayList();
+        classLoaders.add(new SmackConfiguration().getClass().getClassLoader());
+        classLoaders.add(Thread.currentThread().getContextClassLoader());
+        while (classLoaders.remove(null));
+        ClassLoader[] loaders = new ClassLoader[classLoaders.size()];
+        classLoaders.toArray(loaders);
+        return loaders;
     } }

Hey guys,

Thanks for the bug report and fix. FYI, next Smack release will require Java 1.5 or later. The implemented fix, to be available in the next nightly build, requires Java 1.5 or later. BTW, ProviderManager was having the same potential error. Created issue: SMACK-162


– Gato