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/25 22:06:59 UTC

svn commit: r1027251 - in /felix/sandbox/rickhall/bnd-test/org.apache.felix.test.framework.bootdelegation: bnd.bnd src/org/apache/felix/test/framework/bootdelegation/BootDelegationTest.java src/org/apache/felix/test/framework/bootdelegation/HelloImpl.java

Author: rickhall
Date: Mon Oct 25 20:06:59 2010
New Revision: 1027251

URL: http://svn.apache.org/viewvc?rev=1027251&view=rev
Log:
Add reflective test case.

Added:
    felix/sandbox/rickhall/bnd-test/org.apache.felix.test.framework.bootdelegation/src/org/apache/felix/test/framework/bootdelegation/HelloImpl.java
Modified:
    felix/sandbox/rickhall/bnd-test/org.apache.felix.test.framework.bootdelegation/bnd.bnd
    felix/sandbox/rickhall/bnd-test/org.apache.felix.test.framework.bootdelegation/src/org/apache/felix/test/framework/bootdelegation/BootDelegationTest.java

Modified: felix/sandbox/rickhall/bnd-test/org.apache.felix.test.framework.bootdelegation/bnd.bnd
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/bnd-test/org.apache.felix.test.framework.bootdelegation/bnd.bnd?rev=1027251&r1=1027250&r2=1027251&view=diff
==============================================================================
--- felix/sandbox/rickhall/bnd-test/org.apache.felix.test.framework.bootdelegation/bnd.bnd (original)
+++ felix/sandbox/rickhall/bnd-test/org.apache.felix.test.framework.bootdelegation/bnd.bnd Mon Oct 25 20:06:59 2010
@@ -1,4 +1,4 @@
--runvm = -Xdebug, "-Xrunjdwp:transport=dt_socket,address=8001,server=y,suspend=n"
+-runvm = -Xdebug, "-Xrunjdwp:transport=dt_socket,address=8001,server=y,suspend=y"
 
 # Override runpath to include content on class path
 -runpath                = \

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=1027251&r1=1027250&r2=1027251&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 Mon Oct 25 20:06:59 2010
@@ -18,6 +18,7 @@
  */
 package org.apache.felix.test.framework.bootdelegation;
 
+import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
@@ -494,51 +495,25 @@ public class BootDelegationTest extends 
         }
     }
 
-    public void testImplicitBootDelegationWithProxies()
+    public void testImplicitBootDelegationWithReflection()
     {
-        // Try to trigger implicit boot delegation under these conditions:
-        //    - Instigating stack:
-        //      - this bundle class,
-        //      - external class.
-        //    - Class load requested via:
-        //      - Bundle.loadClass().
-        // Implicit boot delegation should NOT occur.
-        InvocationHandler ih = new InvocationHandler() {
-            public Object invoke(Object o, Method method, Object[] os) throws Throwable
-            {
-                // No matter what method is thrown, just print hello.
-                System.out.println("1: Hello from proxied object!");
-                return null;
-            }
-        };
-        Hello hello = (Hello) Proxy.newProxyInstance(
-            this.getClass().getClassLoader(),
-            new Class[] { Hello.class },
-            ih);
-        hello.sayHello();
-
-        // Try to trigger implicit boot delegation under these conditions:
-        //    - Instigating stack:
-        //      - this bundle class,
-        //      - external class.
-        //    - Class load requested via:
-        //      - Bundle.loadClass().
-        // Implicit boot delegation should NOT occur.
-        ih = new InvocationHandler() {
-            public Object invoke(Object o, Method method, Object[] os) throws Throwable
+        // Try to use reflection numerous times (e.g., at least 15) to trigger
+        // internal JVM optimization which causes boot delegation for sun.reflect
+        // classes.
+        // See: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6265952
+        try
+        {
+            for (int i = 0; i < 20; i++)
             {
-                // No matter what method is thrown, just print hello.
-                System.out.println("2: Hello from proxied object!");
-                return null;
+                Constructor ctor = HelloImpl.class.getConstructor((Class[]) null);
+                Object o = ctor.newInstance((Object[]) null);
+                Method m = o.getClass().getDeclaredMethod("sayHello", (Class[]) null);
+                m.invoke(o, (Object[]) null);
             }
-        };
-        hello = (Hello) Proxy.newProxyInstance(
-            this.getClass().getClassLoader(),
-            new Class[] { Hello.class },
-            ih);
-        for (int i = 0; i < 20; i++)
+        }
+        catch (Exception ex)
         {
-            hello.sayHello();
+            fail("Exception while using reflection: " + ex);
         }
     }
 }
\ No newline at end of file

Added: felix/sandbox/rickhall/bnd-test/org.apache.felix.test.framework.bootdelegation/src/org/apache/felix/test/framework/bootdelegation/HelloImpl.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/HelloImpl.java?rev=1027251&view=auto
==============================================================================
--- felix/sandbox/rickhall/bnd-test/org.apache.felix.test.framework.bootdelegation/src/org/apache/felix/test/framework/bootdelegation/HelloImpl.java (added)
+++ felix/sandbox/rickhall/bnd-test/org.apache.felix.test.framework.bootdelegation/src/org/apache/felix/test/framework/bootdelegation/HelloImpl.java Mon Oct 25 20:06:59 2010
@@ -0,0 +1,27 @@
+/*
+ * 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.felix.test.framework.bootdelegation;
+
+public class HelloImpl implements Hello
+{
+    public void sayHello()
+    {
+        System.out.println("+++ HelloImpl says 'Hello'");
+    }
+}
\ No newline at end of file