OSDN Git Service

Modified Thread to copy the context class loader from parent to child threads. Re...
authorcrazybob <crazybob@google.com>
Tue, 16 Jun 2009 17:01:05 +0000 (12:01 -0500)
committercrazybob <crazybob@google.com>
Tue, 16 Jun 2009 17:01:05 +0000 (12:01 -0500)
    doesn't occur if the calling code's class loader is an ancestor of the context class loader).

libcore/luni-kernel/src/main/java/java/lang/Thread.java
libcore/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ThreadTest.java

index d3795f8..3cde7e1 100644 (file)
@@ -508,6 +508,8 @@ public class Thread implements Runnable {
 
         this.priority = currentThread.getPriority();
 
+        this.contextClassLoader = currentThread.contextClassLoader;
+
         // Transfer over InheritableThreadLocals.
         if (currentThread.inheritableValues != null) {
             inheritableValues
index 6ef6d33..47eb166 100644 (file)
@@ -604,8 +604,6 @@ public class ThreadTest extends junit.framework.TestCase {
         method = "getContextClassLoader",
         args = {}
     )
-    @KnownFailure("The context class loader is not inherited by a new thread."
-            + " On android the initial context class loader is alsways null.")
     public void test_getContextClassLoader() {
         // Test for method java.lang.ClassLoader
         // java.lang.Thread.getContextClassLoader()
@@ -614,28 +612,6 @@ public class ThreadTest extends junit.framework.TestCase {
         assertTrue("Incorrect class loader returned",
                 t.getContextClassLoader() == Thread.currentThread()
                         .getContextClassLoader());
-        t.start();
-
- /*       SecurityManager sm = new SecurityManager() {
-
-            public void checkPermission(Permission perm) {
-                if(perm.getName().equals("getClassLoader")) {
-                    throw new SecurityException();
-                }
-            }
-        };
-
-        SecurityManager oldSm = System.getSecurityManager();
-        System.setSecurityManager(sm);
-        try {
-            t.getContextClassLoader();
-            fail("Should throw SecurityException");
-        } catch (SecurityException e) {
-            // expected
-        } finally {
-           System.setSecurityManager(oldSm);
-        }
-*/        
     }
 
     /**