diff options
author | Bryce McKinlay <bryce@waitaki.otago.ac.nz> | 2001-11-04 04:15:09 +0000 |
---|---|---|
committer | Bryce McKinlay <bryce@gcc.gnu.org> | 2001-11-04 04:15:09 +0000 |
commit | cb3f834fb6ad5268fe9640218d7285da0394f857 (patch) | |
tree | bfb510195ffe6d2346162253badade76808f1b85 /libjava/java/util/ResourceBundle.java | |
parent | f5143c46a9cc072c52820b9f903055b153956e77 (diff) | |
download | gcc-cb3f834fb6ad5268fe9640218d7285da0394f857.tar.gz |
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/util/ResourceBundle.java')
-rw-r--r-- | libjava/java/util/ResourceBundle.java | 61 |
1 files changed, 36 insertions, 25 deletions
diff --git a/libjava/java/util/ResourceBundle.java b/libjava/java/util/ResourceBundle.java index f2fa7763d7c..130fc9cfbd6 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()); } /** |