deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject [2/2] deltaspike git commit: DELTASPIKE-782 fix parent ClassLoader lookup
Date Mon, 17 Nov 2014 09:45:59 GMT
DELTASPIKE-782 fix parent ClassLoader lookup

* Don't stop on getSystemClassLoader as this might be perfectly fine in embedded scenarios.
* Properly grab the loadTimeBm from the parent ClassLoader if any


Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/6e62f8eb
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/6e62f8eb
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/6e62f8eb

Branch: refs/heads/master
Commit: 6e62f8eb3048fdffd2ce5fef53d6e338d4c05747
Parents: 115322c
Author: Mark Struberg <struberg@apache.org>
Authored: Mon Nov 17 09:19:42 2014 +0100
Committer: Mark Struberg <struberg@apache.org>
Committed: Mon Nov 17 09:26:05 2014 +0100

----------------------------------------------------------------------
 .../core/api/provider/BeanManagerProvider.java  | 35 +++++++++-----------
 1 file changed, 16 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6e62f8eb/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/provider/BeanManagerProvider.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/provider/BeanManagerProvider.java
b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/provider/BeanManagerProvider.java
index a72bcf3..e349ea9 100644
--- a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/provider/BeanManagerProvider.java
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/provider/BeanManagerProvider.java
@@ -197,17 +197,23 @@ public class BeanManagerProvider implements Extension
     {
         BeanManagerInfo bmi = getBeanManagerInfo(ClassUtils.getClassLoader(null));
 
-        // warn the user if he tries to use the BeanManager before container startup
         if (!bmi.booted)
         {
-            if (!isParentBeanManagerBooted())
-            {
-                LOG.warning("When using the BeanManager to retrieve Beans before the Container
is started," +
-                        " non-portable behaviour results!");
+            // warn the user if he tries to use the BeanManager before container startup
+            LOG.warning("When using the BeanManager to retrieve Beans before the Container
is started," +
+                    " non-portable behaviour results!");
+
 
-                // reset the flag to only issue the warning once.
-                // this is a workaround for some containers which mess up EAR handling.
-                bmi.booted = true;
+            // This is a workaround for some containers with messed up EAR handling.
+            // Those containers might boot up with the shared ear ClassLoader
+            // and later run the WARs with their own child ClassLoaders.
+            if (bmi.loadTimeBm == null)
+            {
+                BeanManagerInfo parentBmi = getParentBeanManagerInfo(ClassUtils.getClassLoader(null));
+                if (parentBmi != null)
+                {
+                    bmi.loadTimeBm = parentBmi.loadTimeBm;
+                }
             }
         }
 
@@ -375,16 +381,6 @@ public class BeanManagerProvider implements Extension
     }
 
     /**
-     * @return whether a BeanManagerInfo for a parent ClassLoader is available and has the
booted flag set.
-     */
-    private boolean isParentBeanManagerBooted()
-    {
-        BeanManagerInfo parentBmi = getParentBeanManagerInfo(ClassUtils.getClassLoader(null));
-
-        return parentBmi != null && parentBmi.booted;
-    }
-
-    /**
      * This method recurses into the parent ClassLoaders and checks whether a BeanManagerInfo
for it exists.
      *
      * @return the BeanManagerInfo of the parent ClassLoader hierarchy if any exists, or
<code>null</code> if there is
@@ -393,7 +389,7 @@ public class BeanManagerProvider implements Extension
     private BeanManagerInfo getParentBeanManagerInfo(ClassLoader classLoader)
     {
         ClassLoader parentClassLoader = classLoader.getParent();
-        if (parentClassLoader == null || parentClassLoader.equals(ClassLoader.getSystemClassLoader()))
+        if (parentClassLoader == null)
         {
             return null;
         }
@@ -401,6 +397,7 @@ public class BeanManagerProvider implements Extension
         BeanManagerInfo bmi = getBeanManagerInfo(parentClassLoader);
         if (bmi == null)
         {
+            // recursive call up to the root ClassLoader
             bmi = getParentBeanManagerInfo(parentClassLoader);
         }
 


Mime
View raw message