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
This commit is contained in:
Bryce McKinlay 2001-11-04 04:15:09 +00:00 committed by Bryce McKinlay
parent f5143c46a9
commit cb3f834fb6
5 changed files with 66 additions and 95 deletions

View file

@ -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
@ -96,6 +90,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.
*/
@ -156,20 +180,6 @@ public abstract class ResourceBundle
("Key not found", getClass().getName(), key);
}
/**
* 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
@ -177,12 +187,13 @@ public abstract class ResourceBundle
* 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());
}
/**

View file

@ -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);
}