Hi,

I committed the attached patch.

Regards,
Jeroen

2007-02-04  Jeroen Frijters  <[EMAIL PROTECTED]>

        * java/lang/Class.java
        (newInstance): Moved setAccessible call to helper method.
        (getEnumConstants): Call new helper method to allow values method to be
        called on non-public enum classes.
        (setAccessible): New helper method.
        * java/lang/Enum.java
        (valueOf): Call new helper method in class to allow field value to
        be read on non-public enum classes.
Index: java/lang/Class.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/lang/Class.java,v
retrieving revision 1.51
diff -u -r1.51 Class.java
--- java/lang/Class.java        11 Dec 2006 00:50:58 -0000      1.51
+++ java/lang/Class.java        3 Feb 2007 13:40:37 -0000
@@ -45,6 +45,7 @@
 import java.io.Serializable;
 import java.lang.annotation.Annotation;
 import java.lang.annotation.Inherited;
+import java.lang.reflect.AccessibleObject;
 import java.lang.reflect.AnnotatedElement;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Field;
@@ -1126,15 +1127,7 @@
        if (!Modifier.isPublic(constructor.getModifiers())
             || !Modifier.isPublic(VMClass.getModifiers(this, true)))
          {
-           final Constructor finalConstructor = constructor;
-           AccessController.doPrivileged(new PrivilegedAction()
-             {
-               public Object run()
-               {
-                 finalConstructor.setAccessible(true);
-                 return null;
-               }
-             });
+           setAccessible(constructor);
          }
        synchronized(this)
          {
@@ -1397,7 +1390,9 @@
       {
        try
          {
-           return (T[]) getMethod("values").invoke(null);
+            Method m = getMethod("values");
+            setAccessible(m);
+           return (T[]) m.invoke(null);
          }
        catch (NoSuchMethodException exception)
          {
@@ -1787,5 +1782,18 @@
     return VMClass.isMemberClass(this);
   }
 
-
+  /**
+   * Utility method for use by classes in this package.
+   */
+  static void setAccessible(final AccessibleObject obj)
+  {
+    AccessController.doPrivileged(new PrivilegedAction()
+      {
+        public Object run()
+          {
+            obj.setAccessible(true);
+            return null;
+          }
+      });
+  }
 }
Index: java/lang/Enum.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/lang/Enum.java,v
retrieving revision 1.6
diff -u -r1.6 Enum.java
--- java/lang/Enum.java 19 Dec 2006 00:37:50 -0000      1.6
+++ java/lang/Enum.java 3 Feb 2007 13:35:58 -0000
@@ -97,9 +97,12 @@
 
     try
       {
+        // XXX We should not use getDeclaredField, because it does
+        // an unnecessary security check.
         Field f = etype.getDeclaredField(s);
         if (! f.isEnumConstant())
           throw new IllegalArgumentException(s);
+        Class.setAccessible(f);
         return (S) f.get(null);
       }
     catch (NoSuchFieldException exception)

Reply via email to