bug fixed for null contextClassLoader

This commit is contained in:
wenshao
2013-07-26 11:41:46 +08:00
parent 19358f2294
commit 02b7870c6a
5 changed files with 86 additions and 33 deletions
@@ -53,20 +53,23 @@ public final class JdbcUtils implements JdbcConstants {
static {
try {
for (Enumeration<URL> e = Thread.currentThread().getContextClassLoader().getResources("META-INF/druid-driver.properties"); e.hasMoreElements();) {
URL url = e.nextElement();
ClassLoader ctxClassLoader = Thread.currentThread().getContextClassLoader();
if (ctxClassLoader != null) {
for (Enumeration<URL> e = ctxClassLoader.getResources("META-INF/druid-driver.properties"); e.hasMoreElements();) {
URL url = e.nextElement();
Properties property = new Properties();
Properties property = new Properties();
InputStream is = null;
try {
is = url.openStream();
property.load(is);
} finally {
JdbcUtils.close(is);
InputStream is = null;
try {
is = url.openStream();
property.load(is);
} finally {
JdbcUtils.close(is);
}
driverUrlMapping.putAll(property);
}
driverUrlMapping.putAll(property);
}
} catch (Exception e) {
LOG.error("load druid-driver.properties error", e);
@@ -486,7 +489,7 @@ public final class JdbcUtils implements JdbcConstants {
// skip
}
}
if (clazz == null) {
try {
ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
@@ -637,10 +640,13 @@ public final class JdbcUtils implements JdbcConstants {
return null;
}
try {
clazz = Thread.currentThread().getContextClassLoader().loadClass(className);
} catch (ClassNotFoundException e) {
ClassLoader ctxClassLoader = Thread.currentThread().getContextClassLoader();
if (ctxClassLoader != null) {
try {
clazz = ctxClassLoader.loadClass(className);
} catch (ClassNotFoundException e) {
// skip
}
}
if (clazz != null) {