For resource loading we won't always have a class loader, so we
need to check for that case. (FELIX-1193)
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@808404 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/framework/src/main/java/org/apache/felix/framework/ModuleImpl.java b/framework/src/main/java/org/apache/felix/framework/ModuleImpl.java
index f342e94..3085f76 100644
--- a/framework/src/main/java/org/apache/felix/framework/ModuleImpl.java
+++ b/framework/src/main/java/org/apache/felix/framework/ModuleImpl.java
@@ -619,7 +619,8 @@
try
{
// Get the appropriate class loader for delegation.
- ClassLoader parent = m_classLoader.getParent();
+ ClassLoader parent = (m_classLoader == null)
+ ? determineParentClassLoader() : m_classLoader.getParent();
parent = (parent == null) ? m_bootClassLoader : parent;
result = (isClass)
? (Object) parent.loadClass(name)
@@ -1267,35 +1268,6 @@
{
if (m_classLoader == null)
{
- // Determine the class loader's parent based on the
- // configuration property; use boot class loader by
- // default.
- String cfg = (String) m_configMap.get(Constants.FRAMEWORK_BUNDLE_PARENT);
- cfg = (cfg == null) ? Constants.FRAMEWORK_BUNDLE_PARENT_BOOT : cfg;
- final ClassLoader parent;
- if (cfg.equalsIgnoreCase(Constants.FRAMEWORK_BUNDLE_PARENT_APP))
- {
- parent = m_secureAction.getSystemClassLoader();
- }
- else if (cfg.equalsIgnoreCase(Constants.FRAMEWORK_BUNDLE_PARENT_EXT))
- {
- parent = m_secureAction.getSystemClassLoader().getParent();
- }
- else if (cfg.equalsIgnoreCase(Constants.FRAMEWORK_BUNDLE_PARENT_FRAMEWORK))
- {
- parent = ModuleImpl.class.getClassLoader();
- }
- // On Android we cannot set the parent class loader to be null, so
- // we special case that situation here and set it to the system
- // class loader by default instead, which is not really spec.
- else if (m_bootClassLoader == null)
- {
- parent = m_secureAction.getSystemClassLoader();
- }
- else
- {
- parent = null;
- }
if (System.getSecurityManager() != null)
{
try
@@ -1303,7 +1275,7 @@
Constructor ctor = (Constructor) m_secureAction.getConstructor(
ModuleClassLoader.class, new Class[] { ClassLoader.class });
m_classLoader = (ModuleClassLoader)
- m_secureAction.invoke(ctor, new Object[] { parent });
+ m_secureAction.invoke(ctor, new Object[] { determineParentClassLoader() });
}
catch (Exception ex)
{
@@ -1312,12 +1284,46 @@
}
else
{
- m_classLoader = new ModuleClassLoader(parent);
+ m_classLoader = new ModuleClassLoader(determineParentClassLoader());
}
}
return m_classLoader;
}
+ private ClassLoader determineParentClassLoader()
+ {
+ // Determine the class loader's parent based on the
+ // configuration property; use boot class loader by
+ // default.
+ String cfg = (String) m_configMap.get(Constants.FRAMEWORK_BUNDLE_PARENT);
+ cfg = (cfg == null) ? Constants.FRAMEWORK_BUNDLE_PARENT_BOOT : cfg;
+ final ClassLoader parent;
+ if (cfg.equalsIgnoreCase(Constants.FRAMEWORK_BUNDLE_PARENT_APP))
+ {
+ parent = m_secureAction.getSystemClassLoader();
+ }
+ else if (cfg.equalsIgnoreCase(Constants.FRAMEWORK_BUNDLE_PARENT_EXT))
+ {
+ parent = m_secureAction.getSystemClassLoader().getParent();
+ }
+ else if (cfg.equalsIgnoreCase(Constants.FRAMEWORK_BUNDLE_PARENT_FRAMEWORK))
+ {
+ parent = ModuleImpl.class.getClassLoader();
+ }
+ // On Android we cannot set the parent class loader to be null, so
+ // we special case that situation here and set it to the system
+ // class loader by default instead, which is not really spec.
+ else if (m_bootClassLoader == null)
+ {
+ parent = m_secureAction.getSystemClassLoader();
+ }
+ else
+ {
+ parent = null;
+ }
+ return parent;
+ }
+
private Object searchImports(String name, boolean isClass)
throws ClassNotFoundException, ResourceNotFoundException
{
@@ -2229,4 +2235,4 @@
return sb.toString();
}
-}
+}
\ No newline at end of file