8152817: Locale data loading fails silently when running with a security manager
Reviewed-by: mchung, alanb
This commit is contained in:
parent
c240356dba
commit
ffd8b1d718
jdk
src
java.base/share/classes/sun/util/resources
jdk.localedata/share/classes/sun/util/resources/provider
test/sun/util/locale/provider
@ -197,8 +197,6 @@ public class LocaleData {
|
||||
|
||||
private static abstract class LocaleDataResourceBundleProvider
|
||||
implements ResourceBundleProvider {
|
||||
abstract protected boolean isSupportedInModule(String baseName, Locale locale);
|
||||
|
||||
/**
|
||||
* Changes baseName to its module dependent package name and
|
||||
* calls the super class implementation. For example,
|
||||
@ -217,10 +215,6 @@ public class LocaleData {
|
||||
* resource bundles except for the java.time supplementary data.
|
||||
*/
|
||||
public static abstract class CommonResourceBundleProvider extends LocaleDataResourceBundleProvider {
|
||||
@Override
|
||||
protected boolean isSupportedInModule(String baseName, Locale locale) {
|
||||
return LocaleDataStrategy.INSTANCE.inJavaBaseModule(baseName, locale);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -228,10 +222,6 @@ public class LocaleData {
|
||||
* resource bundles for java.time.
|
||||
*/
|
||||
public static abstract class SupplementaryResourceBundleProvider extends LocaleDataResourceBundleProvider {
|
||||
@Override
|
||||
protected boolean isSupportedInModule(String baseName, Locale locale) {
|
||||
return SupplementaryStrategy.INSTANCE.inJavaBaseModule(baseName, locale);
|
||||
}
|
||||
}
|
||||
|
||||
// Bundles.Strategy implementations
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -25,34 +25,33 @@
|
||||
|
||||
package sun.util.resources.provider;
|
||||
|
||||
import java.lang.reflect.Module;
|
||||
import java.util.Locale;
|
||||
import java.util.ResourceBundle;
|
||||
import sun.util.locale.provider.ResourceBundleProviderSupport;
|
||||
import sun.util.resources.LocaleData;
|
||||
|
||||
/**
|
||||
* {@code LocaleDataProvider} in module jdk.localedata implements
|
||||
* {@code LocaleDataBundleProvider} in module java.base. This class works as a
|
||||
* service agent between {@code ResourceBundle.getBundle} callers in java.base
|
||||
* and resource bundles in jdk.localedata.
|
||||
* Service Provider for loading locale data resource bundles in jdk.localedata
|
||||
* except for JavaTimeSupplementary resource bundles.
|
||||
*/
|
||||
public class LocaleDataProvider extends LocaleData.CommonResourceBundleProvider {
|
||||
@Override
|
||||
protected boolean isSupportedInModule(String baseName, Locale locale) {
|
||||
// The assumption here is that there are two modules containing
|
||||
// resource bundles for locale support. If resource bundles are split
|
||||
// into more modules, this method will need to be changed to determine
|
||||
// what locales are exactly supported.
|
||||
return !super.isSupportedInModule(baseName, locale);
|
||||
public ResourceBundle getBundle(String baseName, Locale locale) {
|
||||
return loadResourceBundle(toBundleName(baseName, locale));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceBundle getBundle(String baseName, Locale locale) {
|
||||
if (isSupportedInModule(baseName, locale)) {
|
||||
Module module = LocaleDataProvider.class.getModule();
|
||||
String bundleName = toBundleName(baseName, locale);
|
||||
return ResourceBundleProviderSupport.loadResourceBundle(module, bundleName);
|
||||
/**
|
||||
* Utility method for loading a resource bundle in jdk.localedata.
|
||||
*/
|
||||
static ResourceBundle loadResourceBundle(String bundleName) {
|
||||
Class<?> c = Class.forName(LocaleDataProvider.class.getModule(), bundleName);
|
||||
if (c != null && ResourceBundle.class.isAssignableFrom(c)) {
|
||||
try {
|
||||
@SuppressWarnings("unchecked")
|
||||
ResourceBundle rb = ((Class<ResourceBundle>) c).newInstance();
|
||||
return rb;
|
||||
} catch (InstantiationException | IllegalAccessException e) {
|
||||
throw new InternalError(e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -25,33 +25,16 @@
|
||||
|
||||
package sun.util.resources.provider;
|
||||
|
||||
import java.lang.reflect.Module;
|
||||
import java.util.Locale;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import sun.util.locale.provider.ResourceBundleProviderSupport;
|
||||
import sun.util.resources.LocaleData;
|
||||
|
||||
/**
|
||||
* {@code SupplementaryLocaleDataProvider} in module jdk.localedata implements
|
||||
* {@code JavaTimeSupplementaryProvider} in module java.base. This class works as a
|
||||
* service agent between {@code ResourceBundle.getBundle} callers in java.base
|
||||
* and resource bundles in jdk.localedata.
|
||||
* Service Provider for loading JavaTimeSupplementary resource bundles in jdk.localedata.
|
||||
*/
|
||||
public class SupplementaryLocaleDataProvider extends LocaleData.SupplementaryResourceBundleProvider {
|
||||
@Override
|
||||
protected boolean isSupportedInModule(String baseName, Locale locale) {
|
||||
// The assumption here is that there are two modules containing
|
||||
// resource bundles for locale support. If resource bundles are split
|
||||
// into more modules, this method will need to be changed to determine
|
||||
// what locales are exactly supported.
|
||||
return !super.isSupportedInModule(baseName, locale);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceBundle getBundle(String baseName, Locale locale) {
|
||||
Module module = LocaleDataProvider.class.getModule();
|
||||
String bundleName = toBundleName(baseName, locale);
|
||||
return ResourceBundleProviderSupport.loadResourceBundle(module, bundleName);
|
||||
return LocaleDataProvider.loadResourceBundle(toBundleName(baseName, locale));
|
||||
}
|
||||
}
|
||||
|
55
jdk/test/sun/util/locale/provider/Bug8152817.java
Normal file
55
jdk/test/sun/util/locale/provider/Bug8152817.java
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8152817
|
||||
* @summary Make sure that resource bundles in the jdk.localedata module are
|
||||
* loaded under a security manager.
|
||||
* @run main/othervm -Djava.locale.providers=COMPAT
|
||||
* -Djava.security.debug=access,failure,codebase=jrt:/jdk.localedata Bug8152817
|
||||
*/
|
||||
|
||||
import java.text.DateFormatSymbols;
|
||||
import java.time.chrono.HijrahChronology;
|
||||
import java.time.format.TextStyle;
|
||||
import java.util.Calendar;
|
||||
import java.util.Locale;
|
||||
|
||||
public class Bug8152817 {
|
||||
public static void main(String[] args) throws Exception {
|
||||
System.setSecurityManager(new SecurityManager());
|
||||
|
||||
DateFormatSymbols syms = DateFormatSymbols.getInstance(Locale.GERMAN);
|
||||
if (!"Oktober".equals(syms.getMonths()[Calendar.OCTOBER])) {
|
||||
throw new RuntimeException("Test failed (FormatData)");
|
||||
}
|
||||
|
||||
String s = HijrahChronology.INSTANCE.getDisplayName(TextStyle.FULL, Locale.GERMAN);
|
||||
if (!s.contains("Islamischer Kalender")) {
|
||||
throw new RuntimeException("Test failed (JavaTimeSupplementary)");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user