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:50 GMT
Repository: tomee
Updated Branches:
  refs/heads/develop ebe63371a -> ad6bdb23c


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/ad6bdb23
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/ad6bdb23
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/ad6bdb23

Branch: refs/heads/develop
Commit: ad6bdb23c57a6e75640da4748114d988b0101117
Parents: ebe6337
Author: Romain Manni-Bucau <rmannibucau@apache.org>
Authored: Mon Feb 2 10:05:23 2015 +0100
Committer: Romain Manni-Bucau <rmannibucau@apache.org>
Committed: Mon Feb 2 10:05:23 2015 +0100

----------------------------------------------------------------------
 .../tomee/catalina/TomEEWebappClassLoader.java  | 44 ++++++++++++--------
 1 file changed, 27 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/ad6bdb23/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomEEWebappClassLoader.java
----------------------------------------------------------------------
diff --git a/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomEEWebappClassLoader.java
b/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomEEWebappClassLoader.java
index 0461d0e..bd212d2 100644
--- a/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomEEWebappClassLoader.java
+++ b/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomEEWebappClassLoader.java
@@ -176,36 +176,46 @@ public class TomEEWebappClassLoader extends ParallelWebappClassLoader
{
             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);
                     }
                 }
             }
             return super.loadClass(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);
+        }
+    }
 
-    private boolean wouldBeLoadedFromContainer(final String name) {
+    // 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;
         }
     }
 


Mime
View raw message