aboutsummaryrefslogtreecommitdiff
path: root/libjava/java
diff options
context:
space:
mode:
authorBryce McKinlay <bryce@waitaki.otago.ac.nz>2001-11-04 04:15:09 +0000
committerBryce McKinlay <bryce@gcc.gnu.org>2001-11-04 04:15:09 +0000
commitcb3f834fb6ad5268fe9640218d7285da0394f857 (patch)
treebfb510195ffe6d2346162253badade76808f1b85 /libjava/java
parentf5143c46a9cc072c52820b9f903055b153956e77 (diff)
downloadgcc-cb3f834fb6ad5268fe9640218d7285da0394f857.zip
gcc-cb3f834fb6ad5268fe9640218d7285da0394f857.tar.gz
gcc-cb3f834fb6ad5268fe9640218d7285da0394f857.tar.bz2
ResourceBundle.java (getClassContext): Removed.
* java/util/ResourceBundle.java (getClassContext): Removed. (Security): New class, extends SecurityManger. (getBundle): Use Security.getCallingClassLoader instead of getClassContext. * java/util/natResourceBundle.cc: Removed. From-SVN: r46761
Diffstat (limited to 'libjava/java')
-rw-r--r--libjava/java/util/ResourceBundle.java61
-rw-r--r--libjava/java/util/natResourceBundle.cc31
2 files changed, 36 insertions, 56 deletions
diff --git a/libjava/java/util/ResourceBundle.java b/libjava/java/util/ResourceBundle.java
index f2fa776..130fc9c 100644
--- a/libjava/java/util/ResourceBundle.java
+++ b/libjava/java/util/ResourceBundle.java
@@ -28,6 +28,8 @@ executable file might be covered by the GNU General Public License. */
package java.util;
import java.lang.ref.Reference;
import java.lang.ref.SoftReference;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
import gnu.classpath.Configuration;
/**
@@ -74,14 +76,6 @@ import gnu.classpath.Configuration;
* @author Jochen Hoenicke */
public abstract class ResourceBundle
{
- static
- {
- if (Configuration.INIT_LOAD_LIBRARY)
- {
- System.loadLibrary ("javautil");
- }
- }
-
/**
* The parent bundle. This is consulted when you call getObject
* and there is no such resource in the current bundle. This
@@ -97,6 +91,36 @@ public abstract class ResourceBundle
private Locale locale;
/**
+ * We override SecurityManager in order to access getClassContext().
+ */
+ class Security extends SecurityManager
+ {
+ /** Return the ClassLoader of the class which called into this
+ ResourceBundle, or null if it cannot be determined. */
+ ClassLoader getCallingClassLoader()
+ {
+ Class[] stack = super.getClassContext();
+ for (int i = 0; i < stack.length; i++)
+ if (stack[i] != Security.class && stack[i] != ResourceBundle.class)
+ return stack[i].getClassLoader();
+ return null;
+ }
+ }
+
+ // This will always work since java.util classes have (all) system
+ // permissions.
+ static Security security = (Security) AccessController.doPrivileged
+ (
+ new PrivilegedAction()
+ {
+ public Object run()
+ {
+ return new Security();
+ }
+ }
+ );
+
+ /**
* The constructor. It does nothing special.
*/
public ResourceBundle()
@@ -157,32 +181,19 @@ public abstract class ResourceBundle
}
/**
- * This method returns an array with the classes of the calling
- * methods. The zeroth entry is the class that called this method
- * (should always be ResourceBundle), the first contains the class
- * that called the caller (i.e. the class that called getBundle).
- *
- * Implementation note: This depends on the fact, that getBundle
- * doesn't get inlined, but since it calls a private method, it
- * isn't inlineable.
- *
- * @return an array containing the classes for the callers.
- */
- private static native Class[] getClassContext();
-
- /**
* Get the appropriate ResourceBundle for the default locale.
* @param baseName the name of the ResourceBundle. This should be
* a name of a Class or a properties-File. See the class
* description for details.
* @return the desired resource bundle
* @exception MissingResourceException
- * if the resource bundle couldn't be found. */
+ * if the resource bundle couldn't be found.
+ */
public static final ResourceBundle getBundle(String baseName)
throws MissingResourceException
{
return getBundle(baseName, Locale.getDefault(),
- getClassContext()[1].getClassLoader());
+ security.getCallingClassLoader());
}
/**
@@ -199,7 +210,7 @@ public abstract class ResourceBundle
Locale locale)
throws MissingResourceException
{
- return getBundle(baseName, locale, getClassContext()[1].getClassLoader());
+ return getBundle(baseName, locale, security.getCallingClassLoader());
}
/**
diff --git a/libjava/java/util/natResourceBundle.cc b/libjava/java/util/natResourceBundle.cc
deleted file mode 100644
index c9e27b0..0000000
--- a/libjava/java/util/natResourceBundle.cc
+++ /dev/null
@@ -1,31 +0,0 @@
-// natResourceBundle.cc - Native code for ResourceBundle class.
-
-/* Copyright (C) 2001 Free Software Foundation
-
- This file is part of libgcj.
-
-This software is copyrighted work licensed under the terms of the
-Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
-details. */
-
-#include <config.h>
-
-#include <gcj/cni.h>
-#include <jvm.h>
-#include <java/util/ResourceBundle.h>
-#include <java/lang/Class.h>
-#include <java/lang/ClassLoader.h>
-
-JArray<jclass> *
-java::util::ResourceBundle::getClassContext ()
-{
- // FIXME: we currently lack the capability to correctly implement
- // this method. So we fake it by telling ResourceBundle that we
- // only have the system class loader.
- jobjectArray a = JvNewObjectArray (2, &java::lang::Class::class$, NULL);
- jobject *elts = elements (a);
- elts[0] = &class$;
- elts[1] = elts[0];
-
- return reinterpret_cast< JArray<jclass> *> (a);
-}