mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-15 01:42:37 +00:00
ICU-7308 Try Thread.currentThread().getContextClassLoader() before fallback to system class loader based on Deven's suggestion.
X-SVN-Rev: 27177
This commit is contained in:
parent
55e70bfe32
commit
25a81736e6
4 changed files with 41 additions and 16 deletions
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2001-2009, International Business Machines Corporation and *
|
||||
* Copyright (C) 2001-2010, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
@ -573,15 +573,17 @@ public class ICULocaleService extends ICUService {
|
|||
protected ClassLoader loader() {
|
||||
ClassLoader cl = getClass().getClassLoader();
|
||||
if (cl == null) {
|
||||
cl = ClassLoader.getSystemClassLoader();
|
||||
cl = Thread.currentThread().getContextClassLoader();
|
||||
if (cl == null) {
|
||||
//TODO It is not guaranteed that we can get non-null class loader
|
||||
// by Class#getClassLoader() and ClassLoader#getSystemClassLoader()
|
||||
// if the class is loaded by the bootstrap class loader. We should
|
||||
// figure out what to do for such case.
|
||||
throw new RuntimeException("No accessible class loader is available for loading ICU resource bundles.");
|
||||
cl = ClassLoader.getSystemClassLoader();
|
||||
if (cl == null) {
|
||||
//TODO It is not guaranteed that we can get non-null class loader
|
||||
// by the Java specification.
|
||||
throw new RuntimeException("No accessible class loader is available for loading ICU resource bundles.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return cl;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* *****************************************************************************
|
||||
* Copyright (C) 2005-2009, International Business Machines Corporation and *
|
||||
* Copyright (C) 2005-2010, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
* *****************************************************************************
|
||||
*/
|
||||
|
@ -91,8 +91,16 @@ public class ICUResourceBundle extends UResourceBundle {
|
|||
public static final ClassLoader ICU_DATA_CLASS_LOADER;
|
||||
static {
|
||||
ClassLoader loader = ICUData.class.getClassLoader();
|
||||
if (loader == null) { // boot class loader
|
||||
loader = ClassLoader.getSystemClassLoader();
|
||||
if (loader == null) {
|
||||
loader = Thread.currentThread().getContextClassLoader();
|
||||
if (loader == null) {
|
||||
loader = ClassLoader.getSystemClassLoader();
|
||||
if (loader == null) {
|
||||
//TODO It is not guaranteed that we can get non-null class loader
|
||||
// by the Java specification.
|
||||
throw new RuntimeException("No accessible class loader is available for ICUData");
|
||||
}
|
||||
}
|
||||
}
|
||||
ICU_DATA_CLASS_LOADER = loader;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
******************************************************************************
|
||||
* Copyright (C) 2004-2009, International Business Machines Corporation and *
|
||||
* Copyright (C) 2004-2010, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
******************************************************************************
|
||||
*/
|
||||
|
@ -112,8 +112,15 @@ public class ResourceBundleWrapper extends UResourceBundle {
|
|||
protected static synchronized UResourceBundle instantiateBundle(String baseName, String localeID,
|
||||
ClassLoader root, boolean disableFallback) {
|
||||
if (root == null) {
|
||||
// we're on the bootstrap
|
||||
root = ClassLoader.getSystemClassLoader();
|
||||
root = Thread.currentThread().getContextClassLoader();
|
||||
if (root == null) {
|
||||
root = ClassLoader.getSystemClassLoader();
|
||||
if (root == null) {
|
||||
//TODO It is not guaranteed that we can get non-null class loader
|
||||
// by the Java specification.
|
||||
throw new RuntimeException("No accessible class loader is available for resource bundle " + baseName);
|
||||
}
|
||||
}
|
||||
}
|
||||
final ClassLoader cl = root;
|
||||
String name = baseName;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
******************************************************************************
|
||||
* Copyright (C) 2005-2009, International Business Machines Corporation and *
|
||||
* Copyright (C) 2005-2010, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
******************************************************************************
|
||||
*/
|
||||
|
@ -34,9 +34,17 @@ public abstract class URLHandler {
|
|||
|
||||
try {
|
||||
InputStream is = URLHandler.class.getResourceAsStream(PROPNAME);
|
||||
|
||||
if (is == null) {
|
||||
is = ClassLoader.getSystemClassLoader().getResourceAsStream(PROPNAME);
|
||||
ClassLoader loader = Thread.currentThread().getContextClassLoader();
|
||||
if (loader == null) {
|
||||
loader = ClassLoader.getSystemClassLoader();
|
||||
if (loader == null) {
|
||||
//TODO It is not guaranteed that we can get non-null class loader
|
||||
// by the Java specification.
|
||||
throw new RuntimeException("No accessible class loader is available for URLHandler");
|
||||
}
|
||||
}
|
||||
is = loader.getResourceAsStream(PROPNAME);
|
||||
}
|
||||
|
||||
if (is != null) {
|
||||
|
|
Loading…
Add table
Reference in a new issue