diff options
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | java/util/ResourceBundle.java | 61 | ||||
-rw-r--r-- | native/jni/Makefile.am | 3 | ||||
-rw-r--r-- | native/jni/java_util_ResourceBundle.c | 45 |
4 files changed, 46 insertions, 72 deletions
@@ -1,3 +1,12 @@ +2001-11-04 Bryce McKinlay <bryce@waitaki.otago.ac.nz> + + * java/util/ResourceBundle.java (getClassContext): Removed. + (Security): New class, extends SecurityManger. + (getBundle): Use Security.getCallingClassLoader instead of + getClassContext. + * native/jni/java_util_ResourceBundle.c: Removed. + * native/jni/Makefile.am: Updated. + 2001-10-30 Eric Blake <ebb9@email.byu.edu> * java/util/Collections.java: diff --git a/java/util/ResourceBundle.java b/java/util/ResourceBundle.java index f2fa7763d..130fc9cfb 100644 --- a/java/util/ResourceBundle.java +++ b/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/native/jni/Makefile.am b/native/jni/Makefile.am index cc631b585..09eb71aa5 100644 --- a/native/jni/Makefile.am +++ b/native/jni/Makefile.am @@ -47,8 +47,7 @@ libjavanet_la_SOURCES = \ java_net_PlainSocketImpl.c libjavautil_la_SOURCES = \ - java_util_TimeZone.c \ - java_util_ResourceBundle.c + java_util_TimeZone.c libjavaio_la_LDFLAGS = -version-info @LIBVERSION@ libjavalang_la_LDFLAGS = -version-info @LIBVERSION@ diff --git a/native/jni/java_util_ResourceBundle.c b/native/jni/java_util_ResourceBundle.c deleted file mode 100644 index af7e77bef..000000000 --- a/native/jni/java_util_ResourceBundle.c +++ /dev/null @@ -1,45 +0,0 @@ -/* ResourceBundle.c - Native methods for java.util.ResourceBundle - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. - -As a special exception, if you link this library with other files to -produce an executable, this library does not by itself cause the -resulting executable to be covered by the GNU General Public License. -This exception does not however invalidate any other reasons why the -executable file might be covered by the GNU General Public License. */ - - -#include <jni.h> - -#include "java_util_ResourceBundle.h" - -/* - * This is a wrapper to VMSecurityManager.getClassContext(). - * Note that this relies on the fact that native methods aren't listed - * in the returned array. - */ -JNIEXPORT jobjectArray JNICALL -Java_java_util_ResourceBundle_getClassContext(JNIEnv * env, jclass cls) -{ - jclass vmSecManager = (*env)->FindClass(env, "java/lang/VMSecurityManager"); - jmethodID mid = (*env)->GetStaticMethodID(env, vmSecManager, - "getClassContext", - "()[Ljava/lang/Class;"); - return (*env)->CallStaticObjectMethod(env, vmSecManager, mid); -} |