[kaffe] CVS kaffe (robilad): Resynced with GNU Classpath: Proxy

Kaffe CVS cvs-commits at kaffe.org
Sun Jan 9 10:35:44 PST 2005


PatchSet 5826 
Date: 2005/01/09 17:47:40
Author: robilad
Branch: HEAD
Tag: (none) 
Log:
Resynced with GNU Classpath: Proxy

2005-01-09  Dalibor Topic  <robilad at kaffe.org>

* libraries/javalib/java/lang/reflect/Proxy.java:
Resynced with GNU Classpath.

2004-10-15  Michael Koch  <konqueror at gmx.de>

* java/lang/reflect/Proxy.java: Improved javadocs.

2004-10-15  Michael Koch  <konqueror at gmx.de>

* java/lang/reflect/Proxy.java:
Reworked import statements.

2004-10-11  Jeroen Frijters  <jeroen at frijters.net>

* java/lang/reflect/Proxy.java
        (count): Removed useless initializer.

2004-07-10  Jeroen Frijters  <jeroen at frijters.net>

        * java/lang/reflect/Proxy.java (getPackage, ClassFactory): Fixed
        handling of default package. (generate): Removed confused comments
        and code about making Method and Field accessible.

Members: 
	ChangeLog:1.3370->1.3371 
	libraries/javalib/java/lang/reflect/Proxy.java:1.6->1.7 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.3370 kaffe/ChangeLog:1.3371
--- kaffe/ChangeLog:1.3370	Sun Jan  9 17:26:12 2005
+++ kaffe/ChangeLog	Sun Jan  9 17:47:40 2005
@@ -1,5 +1,30 @@
 2005-01-09  Dalibor Topic  <robilad at kaffe.org>
 
+	* libraries/javalib/java/lang/reflect/Proxy.java:
+	Resynced with GNU Classpath.
+
+	2004-10-15  Michael Koch  <konqueror at gmx.de>
+
+	* java/lang/reflect/Proxy.java: Improved javadocs.
+	
+	2004-10-15  Michael Koch  <konqueror at gmx.de>
+	
+	* java/lang/reflect/Proxy.java:
+	Reworked import statements.
+	
+	2004-10-11  Jeroen Frijters  <jeroen at frijters.net>
+	
+	* java/lang/reflect/Proxy.java
+        (count): Removed useless initializer.
+	
+	2004-07-10  Jeroen Frijters  <jeroen at frijters.net>
+
+        * java/lang/reflect/Proxy.java (getPackage, ClassFactory): Fixed
+        handling of default package. (generate): Removed confused comments
+        and code about making Method and Field accessible.
+	
+2005-01-09  Dalibor Topic  <robilad at kaffe.org>
+
 	* libraries/javalib/java/lang/String.java
 	(valueOf): Replaced by implementation from GNU Classpath.
 
Index: kaffe/libraries/javalib/java/lang/reflect/Proxy.java
diff -u kaffe/libraries/javalib/java/lang/reflect/Proxy.java:1.6 kaffe/libraries/javalib/java/lang/reflect/Proxy.java:1.7
--- kaffe/libraries/javalib/java/lang/reflect/Proxy.java:1.6	Sat Dec  4 12:13:59 2004
+++ kaffe/libraries/javalib/java/lang/reflect/Proxy.java	Sun Jan  9 17:47:45 2005
@@ -1,5 +1,5 @@
 /* Proxy.java -- build a proxy class that implements reflected interfaces
-   Copyright (C) 2001, 2002 Free Software Foundation, Inc.
+   Copyright (C) 2001, 2002, 2003, 2004  Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -42,6 +42,7 @@
 import gnu.java.lang.reflect.TypeSignature;
 
 import java.io.Serializable;
+import java.security.ProtectionDomain;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -153,7 +154,7 @@
  * @see InvocationHandler
  * @see UndeclaredThrowableException
  * @see Class
- * @author Eric Blake <ebb9 at email.byu.edu>
+ * @author Eric Blake (ebb9 at email.byu.edu)
  * @since 1.3
  * @status updated to 1.4, except for the use of ProtectionDomain
  */
@@ -270,18 +271,9 @@
                               ? getProxyData0(loader, interfaces)
                               : ProxyData.getProxyData(pt));
 
-            // FIXME workaround for bug in gcj 3.0.x
-            // Not needed with the latest gcj from cvs
-            //clazz = (Configuration.HAVE_NATIVE_GENERATE_PROXY_CLASS
-            //	       ? generateProxyClass0(loader, data)
-            //         : new ClassFactory(data).generate(loader));
-            if (Configuration.HAVE_NATIVE_GENERATE_PROXY_CLASS)
-              clazz = generateProxyClass0(loader, data);
-            else
-              {
-                ClassFactory cf = new ClassFactory(data);
-                clazz = cf.generate(loader);
-              }
+            clazz = (Configuration.HAVE_NATIVE_GENERATE_PROXY_CLASS
+		     ? generateProxyClass0(loader, data)
+                     : new ClassFactory(data).generate(loader));
           }
 
         Object check = proxyClasses.put(pt, clazz);
@@ -731,10 +723,10 @@
   private static final class ProxyData
   {
     /**
-     * The package this class is in.  Possibly null, meaning the unnamed
-     * package.
+     * The package this class is in <b>including the trailing dot</b>
+     * or an empty string for the unnamed (aka default) package.
      */
-    Package pack;
+    String pack;
 
     /**
      * The interfaces this class implements.  Non-null, but possibly empty.
@@ -763,7 +755,7 @@
     /**
      * For unique id's
      */
-    private static int count = 0;
+    private static int count;
 
     /**
      * The id of this proxy class
@@ -778,6 +770,20 @@
     }
 
     /**
+     * Return the name of a package (including the trailing dot)
+     * given the name of a class.
+     * Returns an empty string if no package.  We use this in preference to
+     * using Class.getPackage() to avoid problems with ClassLoaders
+     * that don't set the package.
+     */
+    private static String getPackage(Class k)
+    {
+      String name = k.getName();
+      int idx = name.lastIndexOf('.');
+      return name.substring(0, idx + 1);
+    }
+
+    /**
      * Verifies that the arguments are legal, and sets up remaining data
      * This should only be called when a class must be generated, as
      * it is expensive.
@@ -819,8 +825,8 @@
           if (! Modifier.isPublic(inter.getModifiers()))
             if (in_package)
               {
-                Package p = inter.getPackage();
-                if (data.pack != inter.getPackage())
+		String p = getPackage(inter);
+                if (! data.pack.equals(p))
                   throw new IllegalArgumentException("non-public interfaces "
                                                      + "from different "
                                                      + "packages");
@@ -828,7 +834,7 @@
             else
               {
                 in_package = true;
-                data.pack = inter.getPackage();
+                data.pack = getPackage(inter);
               }
           for (int j = i-1; j >= 0; j--)
             if (data.interfaces[j] == inter)
@@ -955,8 +961,7 @@
       // access_flags
       putU2(Modifier.SUPER | Modifier.FINAL | Modifier.PUBLIC);
       // this_class
-      qualName = ((data.pack == null ? "" : data.pack.getName() + '.')
-                  + "$Proxy" + data.id);
+      qualName = (data.pack + "$Proxy" + data.id);
       putU2(classInfo(TypeSignature.getEncodingOfClass(qualName, false)));
       // super_class
       putU2(classInfo("java/lang/reflect/Proxy"));
@@ -1298,7 +1303,7 @@
      *        implies the bootstrap class loader
      * @return the proxy class Class object
      */
-    final Class generate(ClassLoader loader)
+    Class generate(ClassLoader loader)
     {
       byte[] bytecode = new byte[pool.length() + stream.length()];
       // More efficient to bypass calling charAt() repetitively.
@@ -1319,41 +1324,26 @@
 
       try
         {
-          // XXX Do we require more native support here?
-
-          // XXX Security hole - it is possible for another thread to grab the
-          // VMClassLoader.defineClass Method object, and abuse it while we
-          // have temporarily made it accessible. Do we need to add some
-          // synchronization lock to prevent user reflection while we use it?
-
-          // XXX This is waiting on VM support for protection domains.
-
-          Class vmClassLoader = Class.forName("java.lang.ClassLoader");
-          Class[] types = {String.class,
+          Class vmClassLoader = Class.forName("java.lang.VMClassLoader");
+          Class[] types = {ClassLoader.class, String.class,
                            byte[].class, int.class, int.class,
-                           /* ProtectionDomain.class */ };
+                           ProtectionDomain.class };
           Method m = vmClassLoader.getDeclaredMethod("defineClass", types);
+          // We can bypass the security check of setAccessible(true), since
+	  // we're in the same package.
+          m.flag = true;
 
-          // Bypass the security check of setAccessible(true), since this
-          // is trusted code. But note the comment above about the security
-          // risk of doing this outside a synchronized block.
-          m.setAccessible(true);
-          Object[] args = {qualName, bytecode, new Integer(0),
+          Object[] args = {loader, qualName, bytecode, new Integer(0),
                            new Integer(bytecode.length),
-                           /* Object.class.getProtectionDomain() */ };
-          Class clazz = (Class) m.invoke(loader != null ? loader : ClassLoader.getSystemClassLoader(), args);
-          m.setAccessible(false);
+                           Object.class.getProtectionDomain() };
+          Class clazz = (Class) m.invoke(null, args);
 
           // Finally, initialize the m field of the proxy class, before
           // returning it.
-
-          // No security risk here, since clazz has not been exposed yet,
-          // so user code cannot grab the same reflection object.
           Field f = clazz.getDeclaredField("m");
-          f.setAccessible(true);
+          f.flag = true;
           // we can share the array, because it is not publicized
           f.set(null, methods);
-          f.setAccessible(false);
 
           return clazz;
         }




More information about the kaffe mailing list