tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject tomee git commit: restoring our old ear behavior (ie load from parent if existing) which was broken with recent changes
Date Mon, 02 Feb 2015 09:05:45 GMT
Repository: tomee
Updated Branches:
  refs/heads/tomee-1.7.x 1968f9b33 -> d0962bcfc


restoring our old ear behavior (ie load from parent if existing) which was broken with recent
changes


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

Branch: refs/heads/tomee-1.7.x
Commit: d0962bcfcdf6fd2ae3718131466ed1f544548479
Parents: 1968f9b
Author: Romain Manni-Bucau <rmannibucau@apache.org>
Authored: Mon Feb 2 10:05:10 2015 +0100
Committer: Romain Manni-Bucau <rmannibucau@apache.org>
Committed: Mon Feb 2 10:05:10 2015 +0100

----------------------------------------------------------------------
 .../catalina/LazyStopWebappClassLoader.java     | 47 ++++++++++++--------
 1 file changed, 28 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/d0962bcf/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/LazyStopWebappClassLoader.java
----------------------------------------------------------------------
diff --git a/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/LazyStopWebappClassLoader.java
b/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/LazyStopWebappClassLoader.java
index 672cd66..acae088 100644
--- a/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/LazyStopWebappClassLoader.java
+++ b/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/LazyStopWebappClassLoader.java
@@ -150,13 +150,11 @@ public class LazyStopWebappClassLoader extends WebappClassLoader {
             if (isEar) {
                 final boolean filter = filter(name);
                 filterTempCache.put(name, filter); // will be called again by super.loadClass()
so cache it
-                if (!filter && wouldBeLoadedFromContainer(name)) {
-                    setDelegate(false);
-                    try {
-                        return super.loadClass(name);
-                    } finally {
-                        filterTempCache.remove(name); // no more needed since class is loaded,
avoid to waste mem
-                        setDelegate(originalDelegate);
+                if (!filter) {
+                    if (isTheSame(name, getParent(), containerClassLoader, false, false))
{
+                        return loadWithDelegate(false, name);
+                    } else if (isTheSame(name, getParent(), this, true, originalDelegate))
{
+                        return loadWithDelegate(true, name);
                     }
                 }
             }
@@ -166,27 +164,38 @@ public class LazyStopWebappClassLoader extends WebappClassLoader {
         }
     }
 
-    private boolean wouldBeLoadedFromContainer(final String name) {
+    private Class<?> loadWithDelegate(final boolean delegate, final String name) throws
ClassNotFoundException {
+        setDelegate(delegate);
+        try {
+            return super.loadClass(name);
+        } finally {
+            filterTempCache.remove(name); // no more needed since class is loaded, avoid
to waste mem
+            setDelegate(originalDelegate);
+        }
+    }
+
+    // NOTE: valueIfExistingInBoth should be removed but we need to work really more to make
it a reality
+    private boolean isTheSame(final String name, final ClassLoader c1, final ClassLoader
c2, final Boolean valueIfExistingInBoth, final boolean defaultValue) {
         final String resource = name.replace('.', '/') + CLASS_EXTENSION;
 
-        final URL containerUrl = containerClassLoader.getResource(resource);
-        if (containerUrl == null) {
-            return false;
+        final URL u1 = c1.getResource(resource);
+        if (u1 == null) {
+            return defaultValue;
         }
-
-        final URL parentUrl = getParent().getResource(resource);
-        if (parentUrl == null) {
-            return false;
+        final URL u2 = c2.getResource(resource);
+        if (u2 == null) {
+            return defaultValue;
+        }
+        if (valueIfExistingInBoth != null) {
+            return valueIfExistingInBoth;
         }
         try {
-            return URLs.toFile(parentUrl).getCanonicalPath().equalsIgnoreCase(URLs.toFile(containerUrl).getCanonicalPath());
+            return URLs.toFile(u2).getCanonicalPath().equalsIgnoreCase(URLs.toFile(u1).getCanonicalPath());
         } catch (final IOException e) {
-            return false;
+            return defaultValue;
         }
     }
 
-
-
     @Override
     protected boolean filter(final String name) {
         if ("org.apache.tomee.mojarra.TomEEInjectionProvider".equals(name)) {


Mime
View raw message