You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2013/11/07 11:10:18 UTC

svn commit: r1539582 - in /tomee/tomee/trunk/container/openejb-core/src: main/java/org/apache/openejb/util/classloader/URLClassLoaderFirst.java test/java/org/apache/openejb/classloader/ test/java/org/apache/openejb/classloader/SkipClassesTest.java

Author: rmannibucau
Date: Thu Nov  7 10:10:18 2013
New Revision: 1539582

URL: http://svn.apache.org/r1539582
Log:
TOMEE-1071 .skipping classes supposed in the jvm when they are effectively in the jvm

Added:
    tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/classloader/
    tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/classloader/SkipClassesTest.java
Modified:
    tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/util/classloader/URLClassLoaderFirst.java

Modified: tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/util/classloader/URLClassLoaderFirst.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/util/classloader/URLClassLoaderFirst.java?rev=1539582&r1=1539581&r2=1539582&view=diff
==============================================================================
--- tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/util/classloader/URLClassLoaderFirst.java (original)
+++ tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/util/classloader/URLClassLoaderFirst.java Thu Nov  7 10:10:18 2013
@@ -52,6 +52,8 @@ public class URLClassLoaderFirst extends
     }
 
     public static final String SLF4J_BINDER_CLASS = "org/slf4j/impl/StaticLoggerBinder.class";
+    private static final String CLASS_EXT = ".class";
+    public static final ClassLoader SYSTEM_CLASS_LOADER = ClassLoader.getSystemClassLoader();
 
     public static void reloadConfig() {
         list(FORCED_SKIP, "openejb.classloader.forced-skip");
@@ -202,7 +204,7 @@ public class URLClassLoaderFirst extends
         if (name.startsWith("javax.faces.")) return false;
         if (name.startsWith("javax.mail.")) return false;
         if (name.startsWith("javax.")) return isInServer(name);
-        if (name.startsWith("sun.")) return true;
+        if (name.startsWith("sun.")) return isInJvm(name);
 
         // can be provided in the webapp
         if (name.startsWith("javax.servlet.jsp.jstl")) return false;
@@ -323,7 +325,9 @@ public class URLClassLoaderFirst extends
                 if (swizzle.startsWith("Grep.class") || swizzle.startsWith("Lexer.class")) return true;
                 return false;
             }
-            if (org.startsWith("w3c.dom")) return true;
+            if (org.startsWith("w3c.dom")) {
+                return isInJvm(name);
+            }
             if (org.startsWith("quartz")) return true;
             if (org.startsWith("eclipse.jdt.")) return true;
 
@@ -334,17 +338,16 @@ public class URLClassLoaderFirst extends
         }
 
         // other packages
-        if (name.startsWith("com.sun.")) {
-            final String sun = name.substring("com.sun.".length());
-            if (sun.startsWith("org.apache.")) return true;
-            if (sun.startsWith("crypto.")) return true;
-            return false;
-        }
+        if (name.startsWith("com.sun.")) return isInJvm(name);
         if (name.startsWith("serp.bytecode")) return true;
 
         return false;
     }
 
+    private static boolean isInJvm(final String name) {
+        return SYSTEM_CLASS_LOADER.getResource(name.replace('.', '/') + CLASS_EXT) != null;
+    }
+
     private static boolean isInServer(final String name) {
         if (name.startsWith("javax.")) {
             final String sub = name.substring("javax.".length());

Added: tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/classloader/SkipClassesTest.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/classloader/SkipClassesTest.java?rev=1539582&view=auto
==============================================================================
--- tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/classloader/SkipClassesTest.java (added)
+++ tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/classloader/SkipClassesTest.java Thu Nov  7 10:10:18 2013
@@ -0,0 +1,31 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.openejb.classloader;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.openejb.util.classloader.URLClassLoaderFirst;
+import org.junit.Test;
+
+public class SkipClassesTest {
+    @Test
+    public void checkW3CSkips() {
+        assertTrue(URLClassLoaderFirst.shouldSkip("org.w3c.dom.Comment"));
+        assertFalse(URLClassLoaderFirst.shouldSkip("org.w3c.dom.svg.SVGDocument"));
+    }
+}