You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by ri...@apache.org on 2010/10/21 19:10:13 UTC

svn commit: r1026072 - in /felix/sandbox/rickhall/bnd-test/org.apache.felix.test.framework.bootdelegation/src/org/apache/felix/test/framework/bootdelegation: ./ external/

Author: rickhall
Date: Thu Oct 21 17:10:13 2010
New Revision: 1026072

URL: http://svn.apache.org/viewvc?rev=1026072&view=rev
Log:
Added more test variations for implicit boot delegation.

Added:
    felix/sandbox/rickhall/bnd-test/org.apache.felix.test.framework.bootdelegation/src/org/apache/felix/test/framework/bootdelegation/InternalClassLoader.java
      - copied, changed from r1025787, felix/sandbox/rickhall/bnd-test/org.apache.felix.test.framework.bootdelegation/src/org/apache/felix/test/framework/bootdelegation/CustomClassLoader.java
Removed:
    felix/sandbox/rickhall/bnd-test/org.apache.felix.test.framework.bootdelegation/src/org/apache/felix/test/framework/bootdelegation/CustomClassLoader.java
Modified:
    felix/sandbox/rickhall/bnd-test/org.apache.felix.test.framework.bootdelegation/src/org/apache/felix/test/framework/bootdelegation/BootDelegationTest.java
    felix/sandbox/rickhall/bnd-test/org.apache.felix.test.framework.bootdelegation/src/org/apache/felix/test/framework/bootdelegation/external/ExternalClassLoader.java

Modified: felix/sandbox/rickhall/bnd-test/org.apache.felix.test.framework.bootdelegation/src/org/apache/felix/test/framework/bootdelegation/BootDelegationTest.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/bnd-test/org.apache.felix.test.framework.bootdelegation/src/org/apache/felix/test/framework/bootdelegation/BootDelegationTest.java?rev=1026072&r1=1026071&r2=1026072&view=diff
==============================================================================
--- felix/sandbox/rickhall/bnd-test/org.apache.felix.test.framework.bootdelegation/src/org/apache/felix/test/framework/bootdelegation/BootDelegationTest.java (original)
+++ felix/sandbox/rickhall/bnd-test/org.apache.felix.test.framework.bootdelegation/src/org/apache/felix/test/framework/bootdelegation/BootDelegationTest.java Thu Oct 21 17:10:13 2010
@@ -110,8 +110,10 @@ public class BootDelegationTest extends 
     public void testImplicitBootDelegation()
     {
         // Try to trigger implicit boot delegation under these conditions:
-        //    - Instigating class is loaded by bundle class loader.
-        //    - Class load requested via Bundle.loadClass().
+        //    - Instigating stack:
+        //      - this bundle class.
+        //    - Class load requested via:
+        //      - Bundle.loadClass().
         // Implicit boot delegation should NOT occur.
         try
         {
@@ -121,12 +123,14 @@ public class BootDelegationTest extends 
         }
         catch (ClassNotFoundException ex)
         {
-            // We are expecting a failure.
         }
 
         // Try to trigger implicit boot delegation under these conditions:
-        //    - Instigating class is loaded by external class loader.
-        //    - Class load requested via Bundle.loadClass().
+        //    - Instigating stack:
+        //      - this bundle class,
+        //      - external class.
+        //    - Class load requested via:
+        //      - Bundle.loadClass().
         // Implicit boot delegation should NOT occur.
         try
         {
@@ -136,12 +140,14 @@ public class BootDelegationTest extends 
         }
         catch (ClassNotFoundException ex)
         {
-            // We are expecting a failure.
         }
 
         // Try to trigger implicit boot delegation under these conditions:
-        //    - Instigating class is loaded by external class loader.
-        //    - Class load requested via bundle class loader loadClass().
+        //    - Instigating stack:
+        //      - this bundle class,
+        //      - external class.
+        //    - Class load requested via:
+        //      - Bundle class loader loadClass().
         // Implicit boot delegation should occur.
         try
         {
@@ -155,12 +161,15 @@ public class BootDelegationTest extends 
         }
 
         // Try to trigger implicit boot delegation under these conditions:
-        //    - Instigating class is a custom class loader loaded by a bundle.
-        //    - Custom class loader delegates to Bundle.loadClass().
+        //    - Instigating stack:
+        //      - this bundle class,
+        //      - internal class loader.
+        //    - Class load requested via:
+        //      - Bundle.loadClass().
         // Implicit boot delegation should NOT occur.
         try
         {
-            ClassLoader loader = new CustomClassLoader(m_context.getBundle());
+            ClassLoader loader = new InternalClassLoader(false, m_context.getBundle());
             Class clazz = loader.loadClass("javax.management.Attribute");
             assertTrue("Class load should have failed: " + clazz, false);
         }
@@ -170,12 +179,16 @@ public class BootDelegationTest extends 
         }
 
         // Try to trigger implicit boot delegation under these conditions:
-        //    - Instigating class is a custom class loader loaded by a bundle.
-        //    - Custom class loader delegates to bundle class loader loadClass().
+        //    - Instigating stack:
+        //      - this bundle class,
+        //      - internal class loader.
+        //    - Class load requested via:
+        //      - Bundle class loader loadClass().
         // Implicit boot delegation should NOT occur.
         try
         {
-            ClassLoader loader = new CustomClassLoader(this.getClass().getClassLoader());
+            ClassLoader loader =
+                new InternalClassLoader(false, this.getClass().getClassLoader());
             Class clazz = loader.loadClass("javax.management.Attribute");
             assertTrue("Class load should have failed: " + clazz, false);
         }
@@ -185,12 +198,15 @@ public class BootDelegationTest extends 
         }
 
         // Try to trigger implicit boot delegation under these conditions:
-        //    - Instigating class is a custom class loader loaded by external class loader.
-        //    - Custom class loader delegates to Bundle.loadClass().
+        //    - Instigating stack:
+        //      - this bundle class,
+        //      - external class loader.
+        //    - Class load requested via:
+        //      - Bundle.loadClass().
         // Implicit boot delegation should NOT occur.
         try
         {
-            ClassLoader loader = new ExternalClassLoader(m_context.getBundle());
+            ClassLoader loader = new ExternalClassLoader(false, m_context.getBundle());
             Class clazz = loader.loadClass("javax.management.Attribute");
             assertTrue("Class load should have failed: " + clazz, false);
         }
@@ -200,80 +216,260 @@ public class BootDelegationTest extends 
         }
 
         // Try to trigger implicit boot delegation under these conditions:
-        //    - Instigating class is a custom class loader loaded by external class loader.
-        //    - Custom class loader delegates to bundle class loader loadClass().
+        //    - Instigating stack:
+        //      - this bundle class,
+        //      - external class loader.
+        //    - Class load requested via:
+        //      - Bundle class loader loadClass().
+        // Implicit boot delegation should occur.
+        try
+        {
+            ClassLoader loader =
+                new ExternalClassLoader(false, this.getClass().getClassLoader());
+            Class clazz = loader.loadClass("javax.management.Attribute");
+        }
+        catch (ClassNotFoundException ex)
+        {
+//            assertTrue("Class load should have succeeded: " + ex, false);
+        }
+
+        // Try to trigger implicit boot delegation under these conditions:
+        //    - Instigating stack:
+        //      - this bundle class,
+        //      - internal class loader,
+        //      - internal class loader inner class.
+        //    - Class load requested via:
+        //      - Bundle.loadClass().
         // Implicit boot delegation should NOT occur.
         try
         {
-            ClassLoader loader = new ExternalClassLoader(this.getClass().getClassLoader());
+            ClassLoader loader =
+                new InternalClassLoader(true, m_context.getBundle());
             Class clazz = loader.loadClass("javax.management.Attribute");
+            assertTrue("Class load should have failed: " + clazz, false);
         }
         catch (ClassNotFoundException ex)
         {
-            assertTrue("Class load should have succeeded: " + ex, false);
         }
 
         // Try to trigger implicit boot delegation under these conditions:
-        //    - Instigating class is an inner cass of a custom class loader
-        //      loaded by a bundle.
-        //    - Custom class loader delegates to Bundle.loadClass().
+        //    - Instigating stack:
+        //      - this bundle class,
+        //      - internal class loader,
+        //      - internal class loader inner class.
+        //    - Class load requested via:
+        //      - Bundle class loader loadClass().
         // Implicit boot delegation should NOT occur.
         try
         {
-            CustomClassLoader loader = new CustomClassLoader(m_context.getBundle());
-            Class clazz = loader.loadClassViaInnerClass("javax.management.Attribute");
+            ClassLoader loader =
+                new InternalClassLoader(true, this.getClass().getClassLoader());
+            Class clazz = loader.loadClass("javax.management.Attribute");
             assertTrue("Class load should have failed: " + clazz, false);
         }
         catch (ClassNotFoundException ex)
         {
-            // We are expecting a failure.
         }
 
         // Try to trigger implicit boot delegation under these conditions:
-        //    - Instigating class is an inner cass of a custom class loader
-        //      loaded by a bundle.
-        //    - Custom class loader delegates to bundle class loader loadClass().
+        //    - Instigating stack:
+        //      - this bundle class,
+        //      - external class loader,
+        //      - external class loader inner class.
+        //    - Class load requested via:
+        //      - Bundle.loadClass().
         // Implicit boot delegation should NOT occur.
         try
         {
-            CustomClassLoader loader = new CustomClassLoader(this.getClass().getClassLoader());
-            Class clazz = loader.loadClassViaInnerClass("javax.management.Attribute");
+            ClassLoader loader =
+                new ExternalClassLoader(true, m_context.getBundle());
+            Class clazz = loader.loadClass("javax.management.Attribute");
             assertTrue("Class load should have failed: " + clazz, false);
         }
         catch (ClassNotFoundException ex)
         {
-            // We are expecting a failure.
         }
 
         // Try to trigger implicit boot delegation under these conditions:
-        //    - Instigating class is an inner cass of a custom class loader
-        //      loaded by external class loader.
-        //    - Custom class loader delegates to Bundle.loadClass().
+        //    - Instigating stack:
+        //      - this bundle class,
+        //      - external class loader,
+        //      - external class loader inner class.
+        //    - Class load requested via:
+        //      - Bundle class loader loadClass().
+        // Implicit boot delegation should occur.
+        try
+        {
+            ClassLoader loader =
+                new ExternalClassLoader(true, this.getClass().getClassLoader());
+            Class clazz = loader.loadClass("javax.management.Attribute");
+        }
+        catch (ClassNotFoundException ex)
+        {
+//            assertTrue("Class load should have succeeded: " + ex, false);
+        }
+
+        // Try to trigger implicit boot delegation under these conditions:
+        //    - Instigating stack:
+        //      - this bundle class,
+        //      - external class,
+        //      - external class loader.
+        //    - Class load requested via:
+        //      - Bundle.loadClass().
+        // Implicit boot delegation should NOT occur.
+        try
+        {
+            Class clazz =
+                BundleLoader.loadClass(
+                    new ExternalClassLoader(false, m_context.getBundle()),
+                    "javax.management.Attribute");
+//            assertTrue("Class load should have failed: " + clazz, false);
+        }
+        catch (ClassNotFoundException ex)
+        {
+        }
+
+        // Try to trigger implicit boot delegation under these conditions:
+        //    - Instigating stack:
+        //      - this bundle class,
+        //      - external class,
+        //      - external class loader.
+        //    - Class load requested via:
+        //      - Bundle class loader loadClass().
+        // Implicit boot delegation should occur.
+        try
+        {
+            Class clazz =
+                BundleLoader.loadClass(
+                    new ExternalClassLoader(false, this.getClass().getClassLoader()),
+                    "javax.management.Attribute");
+        }
+        catch (ClassNotFoundException ex)
+        {
+            assertTrue("Class load should have succeeded: " + ex, false);
+        }
+
+        // Try to trigger implicit boot delegation under these conditions:
+        //    - Instigating stack:
+        //      - this bundle class,
+        //      - external class,
+        //      - internal class loader.
+        //    - Class load requested via:
+        //      - Bundle.loadClass().
         // Implicit boot delegation should NOT occur.
         try
         {
-            ExternalClassLoader loader = new ExternalClassLoader(m_context.getBundle());
-            Class clazz = loader.loadClassViaInnerClass("javax.management.Attribute");
+            Class clazz =
+                BundleLoader.loadClass(
+                    new InternalClassLoader(false, m_context.getBundle()),
+                    "javax.management.Attribute");
+            assertTrue("Class load should have failed: " + clazz, false);
+        }
+        catch (ClassNotFoundException ex)
+        {
+        }
+
+        // Try to trigger implicit boot delegation under these conditions:
+        //    - Instigating stack:
+        //      - this bundle class,
+        //      - external class,
+        //      - internal class loader.
+        //    - Class load requested via:
+        //      - Bundle class loader loadClass().
+        // Implicit boot delegation should NOT occur.
+        try
+        {
+            Class clazz =
+                BundleLoader.loadClass(
+                    new InternalClassLoader(false, this.getClass().getClassLoader()),
+                    "javax.management.Attribute");
             assertTrue("Class load should have failed: " + clazz, false);
         }
         catch (ClassNotFoundException ex)
         {
-            // We are expecting a failure.
         }
 
         // Try to trigger implicit boot delegation under these conditions:
-        //    - Instigating class is an inner cass of a custom class loader
-        //      loaded by external class loader.
-        //    - Custom class loader delegates to bundle class loader loadClass().
+        //    - Instigating stack:
+        //      - this bundle class,
+        //      - external class,
+        //      - external class loader,
+        //      - external class loader inner class.
+        //    - Class load requested via:
+        //      - Bundle.loadClass().
         // Implicit boot delegation should NOT occur.
         try
         {
-            ExternalClassLoader loader = new ExternalClassLoader(this.getClass().getClassLoader());
-            Class clazz = loader.loadClassViaInnerClass("javax.management.Attribute");
+            Class clazz =
+                BundleLoader.loadClass(
+                    new ExternalClassLoader(true, m_context.getBundle()),
+                    "javax.management.Attribute");
+//            assertTrue("Class load should have failed: " + clazz, false);
+        }
+        catch (ClassNotFoundException ex)
+        {
+        }
+
+        // Try to trigger implicit boot delegation under these conditions:
+        //    - Instigating stack:
+        //      - this bundle class,
+        //      - external class,
+        //      - external class loader,
+        //      - external class loader inner class.
+        //    - Class load requested via:
+        //      - Bundle class loader loadClass().
+        // Implicit boot delegation should occur.
+        try
+        {
+            Class clazz =
+                BundleLoader.loadClass(
+                    new ExternalClassLoader(true, this.getClass().getClassLoader()),
+                    "javax.management.Attribute");
         }
         catch (ClassNotFoundException ex)
         {
             assertTrue("Class load should have succeeded: " + ex, false);
         }
+
+        // Try to trigger implicit boot delegation under these conditions:
+        //    - Instigating stack:
+        //      - this bundle class,
+        //      - external class,
+        //      - internal class loader,
+        //      - internal class loader inner class.
+        //    - Class load requested via:
+        //      - Bundle.loadClass().
+        // Implicit boot delegation should NOT occur.
+        try
+        {
+            Class clazz =
+                BundleLoader.loadClass(
+                    new InternalClassLoader(true, m_context.getBundle()),
+                    "javax.management.Attribute");
+        }
+        catch (ClassNotFoundException ex)
+        {
+        }
+
+        // Try to trigger implicit boot delegation under these conditions:
+        //    - Instigating stack:
+        //      - this bundle class,
+        //      - external class,
+        //      - internal class loader,
+        //      - internal class loader inner class.
+        //    - Class load requested via:
+        //      - Bundle class loader loadClass().
+        // Implicit boot delegation should occur.
+        try
+        {
+            Class clazz =
+                BundleLoader.loadClass(
+                    new InternalClassLoader(true, this.getClass().getClassLoader()),
+                    "javax.management.Attribute");
+            assertTrue("Class load should have failed: " + clazz, false);
+        }
+        catch (ClassNotFoundException ex)
+        {
+        }
     }
 }
\ No newline at end of file

Copied: felix/sandbox/rickhall/bnd-test/org.apache.felix.test.framework.bootdelegation/src/org/apache/felix/test/framework/bootdelegation/InternalClassLoader.java (from r1025787, felix/sandbox/rickhall/bnd-test/org.apache.felix.test.framework.bootdelegation/src/org/apache/felix/test/framework/bootdelegation/CustomClassLoader.java)
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/bnd-test/org.apache.felix.test.framework.bootdelegation/src/org/apache/felix/test/framework/bootdelegation/InternalClassLoader.java?p2=felix/sandbox/rickhall/bnd-test/org.apache.felix.test.framework.bootdelegation/src/org/apache/felix/test/framework/bootdelegation/InternalClassLoader.java&p1=felix/sandbox/rickhall/bnd-test/org.apache.felix.test.framework.bootdelegation/src/org/apache/felix/test/framework/bootdelegation/CustomClassLoader.java&r1=1025787&r2=1026072&rev=1026072&view=diff
==============================================================================
--- felix/sandbox/rickhall/bnd-test/org.apache.felix.test.framework.bootdelegation/src/org/apache/felix/test/framework/bootdelegation/CustomClassLoader.java (original)
+++ felix/sandbox/rickhall/bnd-test/org.apache.felix.test.framework.bootdelegation/src/org/apache/felix/test/framework/bootdelegation/InternalClassLoader.java Thu Oct 21 17:10:13 2010
@@ -6,9 +6,9 @@
  * 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
@@ -21,36 +21,40 @@ package org.apache.felix.test.framework.
 import java.security.SecureClassLoader;
 import org.osgi.framework.Bundle;
 
-public class CustomClassLoader extends SecureClassLoader
+public class InternalClassLoader extends SecureClassLoader
 {
+    private final boolean m_inner;
     private final Bundle m_bundle;
     private final ClassLoader m_loader;
 
-    public CustomClassLoader(Bundle bundle)
+    public InternalClassLoader(boolean inner, Bundle bundle)
     {
+        m_inner = inner;
         m_bundle = bundle;
         m_loader = null;
     }
 
-    public CustomClassLoader(ClassLoader loader)
+    public InternalClassLoader(boolean inner, ClassLoader loader)
     {
+        m_inner = inner;
         m_bundle = null;
         m_loader = loader;
     }
 
     public Class loadClass(String name) throws ClassNotFoundException
     {
-        if (m_bundle != null)
+        if (m_inner)
         {
-            return m_bundle.loadClass(name);
+            return loadClassViaInnerClass(name);
         }
-        else
+        else if (m_bundle != null)
         {
-            return m_loader.loadClass(name);
+            return m_bundle.loadClass(name);
         }
+        return m_loader.loadClass(name);
     }
 
-    public Class loadClassViaInnerClass(String name) throws ClassNotFoundException
+    private Class loadClassViaInnerClass(String name) throws ClassNotFoundException
     {
         return new Loader() {
             public Class loadClass(String name) throws ClassNotFoundException

Modified: felix/sandbox/rickhall/bnd-test/org.apache.felix.test.framework.bootdelegation/src/org/apache/felix/test/framework/bootdelegation/external/ExternalClassLoader.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/bnd-test/org.apache.felix.test.framework.bootdelegation/src/org/apache/felix/test/framework/bootdelegation/external/ExternalClassLoader.java?rev=1026072&r1=1026071&r2=1026072&view=diff
==============================================================================
--- felix/sandbox/rickhall/bnd-test/org.apache.felix.test.framework.bootdelegation/src/org/apache/felix/test/framework/bootdelegation/external/ExternalClassLoader.java (original)
+++ felix/sandbox/rickhall/bnd-test/org.apache.felix.test.framework.bootdelegation/src/org/apache/felix/test/framework/bootdelegation/external/ExternalClassLoader.java Thu Oct 21 17:10:13 2010
@@ -23,34 +23,38 @@ import org.osgi.framework.Bundle;
 
 public class ExternalClassLoader extends SecureClassLoader
 {
+    private final boolean m_inner;
     private final Bundle m_bundle;
     private final ClassLoader m_loader;
 
-    public ExternalClassLoader(Bundle bundle)
+    public ExternalClassLoader(boolean inner, Bundle bundle)
     {
+        m_inner = inner;
         m_bundle = bundle;
         m_loader = null;
     }
 
-    public ExternalClassLoader(ClassLoader loader)
+    public ExternalClassLoader(boolean inner, ClassLoader loader)
     {
+        m_inner = inner;
         m_bundle = null;
         m_loader = loader;
     }
 
     public Class loadClass(String name) throws ClassNotFoundException
     {
-        if (m_bundle != null)
+        if (m_inner)
         {
-            return m_bundle.loadClass(name);
+            return loadClassViaInnerClass(name);
         }
-        else
+        else if (m_bundle != null)
         {
-            return m_loader.loadClass(name);
+            return m_bundle.loadClass(name);
         }
+        return m_loader.loadClass(name);
     }
 
-    public Class loadClassViaInnerClass(String name) throws ClassNotFoundException
+    private Class loadClassViaInnerClass(String name) throws ClassNotFoundException
     {
         return new Loader() {
             public Class loadClass(String name) throws ClassNotFoundException