From 8879234bbc14537d3680e7db0ec983cb64516f83 Mon Sep 17 00:00:00 2001 From: Gaston Dombiak Date: Wed, 2 Aug 2006 22:31:23 +0000 Subject: [PATCH] Fixed potential error when #getClassLoader returns null. SMACK-162 git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@4774 b35dd754-fafc-0310-a699-88a17e54d16e --- .../org/jivesoftware/smack/SmackConfiguration.java | 13 +++++++++++-- .../smack/provider/ProviderManager.java | 9 ++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/source/org/jivesoftware/smack/SmackConfiguration.java b/source/org/jivesoftware/smack/SmackConfiguration.java index 2e83f56f1..86d144112 100644 --- a/source/org/jivesoftware/smack/SmackConfiguration.java +++ b/source/org/jivesoftware/smack/SmackConfiguration.java @@ -25,7 +25,9 @@ import org.xmlpull.v1.XmlPullParser; import java.io.InputStream; import java.net.URL; +import java.util.ArrayList; import java.util.Enumeration; +import java.util.List; /** * Represents the configuration of Smack. The configuration is used for: @@ -129,7 +131,7 @@ public final class SmackConfiguration { public static int getPacketReplyTimeout() { // The timeout value must be greater than 0 otherwise we will answer the default value if (packetReplyTimeout <= 0) { - packetReplyTimeout = 5000; + packetReplyTimeout = 5000; } return packetReplyTimeout; } @@ -204,6 +206,13 @@ public final class SmackConfiguration { ClassLoader[] classLoaders = new ClassLoader[2]; classLoaders[0] = SmackConfiguration.class.getClassLoader(); classLoaders[1] = Thread.currentThread().getContextClassLoader(); - return classLoaders; + // Clean up possible null values. Note that #getClassLoader may return a null value. + List loaders = new ArrayList(); + for (ClassLoader classLoader : classLoaders) { + if (classLoader != null) { + loaders.add(classLoader); + } + } + return (ClassLoader[]) loaders.toArray(); } } diff --git a/source/org/jivesoftware/smack/provider/ProviderManager.java b/source/org/jivesoftware/smack/provider/ProviderManager.java index 0d4bba526..d94a8e603 100644 --- a/source/org/jivesoftware/smack/provider/ProviderManager.java +++ b/source/org/jivesoftware/smack/provider/ProviderManager.java @@ -384,7 +384,14 @@ public class ProviderManager { ClassLoader[] classLoaders = new ClassLoader[2]; classLoaders[0] = ProviderManager.class.getClassLoader(); classLoaders[1] = Thread.currentThread().getContextClassLoader(); - return classLoaders; + // Clean up possible null values. Note that #getClassLoader may return a null value. + List loaders = new ArrayList(); + for (ClassLoader classLoader : classLoaders) { + if (classLoader != null) { + loaders.add(classLoader); + } + } + return (ClassLoader[]) loaders.toArray(); } private ProviderManager() {