harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From var...@apache.org
Subject svn commit: r597401 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/lang/reflect/Proxy.java test/api/common/tests/api/java/lang/reflect/ProxyTest.java
Date Thu, 22 Nov 2007 12:57:27 GMT
Author: varlax
Date: Thu Nov 22 04:57:22 2007
New Revision: 597401

URL: http://svn.apache.org/viewvc?rev=597401&view=rev
Log:
Fixed HARMONY-5173 [classlib][luni] Proxy.getProxyClass() converts bootstrap classloader to
system one
+ corrected pattern for exception asserts.

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/reflect/Proxy.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/lang/reflect/ProxyTest.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/reflect/Proxy.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/reflect/Proxy.java?rev=597401&r1=597400&r2=597401&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/reflect/Proxy.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/reflect/Proxy.java
Thu Nov 22 04:57:22 2007
@@ -151,9 +151,6 @@
                 }
                 byte[] classFileBytes = ProxyClassFile.generateBytes(
                         nextClassName, interfaces);
-                if (loader == null) {
-                    loader = ClassLoader.getSystemClassLoader();
-                }
                 newClass = defineClassImpl(loader, nextClassName.replace('.',
                         '/'), classFileBytes);
                 // Need a weak reference to the class so it can

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/lang/reflect/ProxyTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/lang/reflect/ProxyTest.java?rev=597401&r1=597400&r2=597401&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/lang/reflect/ProxyTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/lang/reflect/ProxyTest.java
Thu Nov 22 04:57:22 2007
@@ -22,6 +22,9 @@
 import java.lang.reflect.Proxy;
 import java.lang.reflect.UndeclaredThrowableException;
 
+import java.security.AllPermission;
+import java.security.ProtectionDomain;
+
 import tests.support.Support_Proxy_I1;
 import tests.support.Support_Proxy_I2;
 import tests.support.Support_Proxy_ParentException;
@@ -72,21 +75,19 @@
 				.isProxyClass(Proxy.getProxyClass(null,
 						new Class[] { Comparable.class })));
 
-		boolean aborted = false;
 		try {
 			Proxy.getProxyClass(null, new Class[] { Support_Proxy_I1.class,
 					Support_Proxy_I2.class });
-		} catch (IllegalArgumentException e) {
-			aborted = true;
+            fail("Default classLoader should not see app class ");
+		} catch (IllegalArgumentException expected) {
 		}
-		assertTrue("Default classLoader should not see app class ", aborted);
 	}
 
 	/**
 	 * @tests java.lang.reflect.Proxy#newProxyInstance(java.lang.ClassLoader,
 	 *        java.lang.Class[], java.lang.reflect.InvocationHandler)
 	 */
-	public void test_newProxyInstanceLjava_lang_ClassLoader$Ljava_lang_ClassLjava_lang_reflect_InvocationHandler()
{
+	public void test_newProxyInstanceLjava_lang_ClassLoader$Ljava_lang_ClassLjava_lang_reflect_InvocationHandler()
throws Exception {
 		Object p = Proxy.newProxyInstance(Support_Proxy_I1.class
 				.getClassLoader(), new Class[] { Support_Proxy_I1.class,
 				Support_Proxy_I2.class }, new InvocationHandler() {
@@ -116,42 +117,31 @@
 		int[] result = (int[]) proxy.array(new long[] { 100L, -200L });
 		assertEquals("Failed base type conversion test ", -200, result[0]);
 
-		boolean worked = false;
 		try {
 			proxy.string("");
+            fail("Problem converting exception");
 		} catch (Support_Proxy_SubException e) {
-			worked = true;
-		} catch (Support_Proxy_ParentException e) { // is never thrown
 		}
-		assertTrue("Problem converting exception ", worked);
 
-		worked = false;
 		try {
 			proxy.string("clone");
-		} catch (Support_Proxy_ParentException e) { // is never thrown
+            fail("Problem converting exception");
 		} catch (UndeclaredThrowableException e) {
-			worked = true;
+            assertSame(Support_Proxy_ParentException.class, e.getCause().getClass());
 		}
-		assertTrue("Problem converting exception ", worked);
 
-		worked = false;
 		try {
 			proxy.string("error");
-		} catch (Support_Proxy_ParentException e) { // is never thrown
-		} catch (UndeclaredThrowableException e) {
-		} catch (RuntimeException e) {
-			worked = e.getClass() == ArrayStoreException.class;
+            fail("Problem converting exception");
+		} catch (ArrayStoreException e) {
 		}
-		assertTrue("Problem converting exception ", worked);
 
-		worked = false;
 		try {
 			proxy.string("any");
-		} catch (Support_Proxy_ParentException e) { // is never thrown
+            fail("Problem converting exception");
 		} catch (UndeclaredThrowableException e) {
-			worked = true;
+            assertSame(IllegalAccessException.class, e.getCause().getClass());
 		}
-		assertTrue("Problem converting exception ", worked);
 
 		Broken1 proxyObject = (Broken1) Proxy.newProxyInstance(Broken1.class
 				.getClassLoader(), new Class[] { Broken1.class },
@@ -207,13 +197,11 @@
 
 		assertTrue("Did not return invocation handler ", Proxy
 				.getInvocationHandler(p) == handler);
-		boolean aborted = false;
 		try {
 			Proxy.getInvocationHandler("");
+            fail("Did not detect non proxy object");
 		} catch (IllegalArgumentException e) {
-			aborted = true;
 		}
-		assertTrue("Did not detect non proxy object ", aborted);
 	}
         
     //Regression Test for HARMONY-2355
@@ -226,6 +214,31 @@
         assertNotNull(o);
     }
 
+    public void test_getProxyClass_loader() {
+        Class pc = Proxy.getProxyClass(null,
+                new Class[] { Runnable.class});
+        assertSame(null, pc.getClassLoader());
+        
+        ProtectionDomain pd = pc.getProtectionDomain();
+        ProtectionDomain od = Object.class.getProtectionDomain();
+        assertTrue(pd.implies(new AllPermission()));
+        assertSame(od.getClassLoader(), pd.getClassLoader());
+        assertEquals(od.toString(), pd.toString());
+    }
+
+    public void test_getProxyClass_package() {
+        Class pc = Proxy.getProxyClass(PkgIntf.class.getClassLoader(),
+                new Class[] { PkgIntf.class});
+        assertSame(PkgIntf.class.getPackage(), pc.getPackage());
+        assertSame(PkgIntf.class.getClassLoader(), pc.getClassLoader());
+        
+        ProtectionDomain pd = pc.getProtectionDomain();
+        ProtectionDomain od = Object.class.getProtectionDomain();
+        assertTrue(pd.implies(new AllPermission()));
+        assertSame(od.getClassLoader(), pd.getClassLoader());
+        assertEquals(od.toString(), pd.toString());
+    }
+
     public void test_newProxyInstance_withNonCompatibleReturnTypes() {
         try {
             Proxy.newProxyInstance(this.getClass().getClassLoader(),
@@ -280,3 +293,5 @@
 	protected void tearDown() {
 	}
 }
+
+interface PkgIntf {}



Mime
View raw message