This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch: RFC: PR 27352


This patch fixes PR 27352 by adding a getClassLoaderInternal() implementation in Java. This is a shortcut implementation of getClassLoader() that bypasses redundant security manager checks. getClassLoaderInternal() was already used from natClass.cc, but it couldn't be used from Java code because it was only defined in Class.h.

Any comments/objections? Otherwise, I'll check this in to trunk tomorrow.

Bryce

2006-05-15  Bryce McKinlay  <mckinlay@redhat.com>

	PR libgcj/27352
	* java/lang/Class.java (getClassLoaderInternal): New method.
	(forName (String, Class)): Use getClassLoaderInternal.
	(getPackage): Likewise.
	(getResource): Likewise.
	(getResourceAsStream): Likewise.
	(desiredAssertionStatus): Likewise.

Index: java/lang/Class.java
===================================================================
--- java/lang/Class.java	(revision 113809)
+++ java/lang/Class.java	(working copy)
@@ -115,7 +115,7 @@
   private static Class forName (String className, Class caller)
     throws ClassNotFoundException
   {
-    return forName(className, true, caller.getClassLoader());
+    return forName(className, true, caller.getClassLoaderInternal());
   }
 
 
@@ -192,11 +192,20 @@
    * @see RuntimePermission
    */
   public native ClassLoader getClassLoader ();
-  
+
   // A private internal method that is called by compiler-generated code.
   private final native ClassLoader getClassLoader (Class caller);
-  
+
   /**
+   *  Internal method that circumvents the usual security checks when 
+   *  getting the class loader.
+   */
+  private ClassLoader getClassLoaderInternal ()
+  {
+    return loader;
+  }
+
+  /**
    * If this is an array, get the Class representing the type of array.
    * Examples: "[[Ljava.lang.String;" would return "[Ljava.lang.String;", and
    * calling getComponentType on that would give "java.lang.String".  If
@@ -473,7 +482,7 @@
    */
   public Package getPackage()
   {
-    ClassLoader cl = getClassLoader();
+    ClassLoader cl = getClassLoaderInternal();
     if (cl != null)
       return cl.getPackage(getPackagePortion(getName()));
     else
@@ -616,7 +625,7 @@
   public URL getResource(String resourceName)
   {
     String name = resourcePath(resourceName);
-    ClassLoader loader = getClassLoader();
+    ClassLoader loader = getClassLoaderInternal();
     if (loader == null)
       return ClassLoader.getSystemResource(name);
     return loader.getResource(name);
@@ -644,7 +653,7 @@
   public InputStream getResourceAsStream(String resourceName)
   {
     String name = resourcePath(resourceName);
-    ClassLoader loader = getClassLoader();
+    ClassLoader loader = getClassLoaderInternal();
     if (loader == null)
       return ClassLoader.getSystemResourceAsStream(name);
     return loader.getResourceAsStream(name);
@@ -839,7 +848,7 @@
    */
   public boolean desiredAssertionStatus()
   {
-    ClassLoader c = getClassLoader();
+    ClassLoader c = getClassLoaderInternal();
     Object status;
     if (c == null)
       return VMClassLoader.defaultAssertionStatus();

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]