8171189: Deprecate ResourceBundleControlProvider for removal

Reviewed-by: mchung
This commit is contained in:
Naoto Sato 2016-12-19 09:56:11 -08:00
parent 7a50f217c2
commit 004901e102
12 changed files with 12 additions and 427 deletions

View File

@ -60,7 +60,6 @@ import java.security.PrivilegedExceptionAction;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.jar.JarEntry;
import java.util.spi.ResourceBundleControlProvider;
import java.util.spi.ResourceBundleProvider;
import jdk.internal.loader.BootLoader;
@ -232,8 +231,6 @@ import static sun.security.util.SecurityConstants.GET_CLASSLOADER_PERMISSION;
* <li>{@code ResourceBundle.Control} is <em>not</em> supported in named modules.
* If the {@code getBundle} method with a {@code ResourceBundle.Control} is called
* in a named module, the method will throw an {@code UnsupportedOperationException}.
* Any service providers of {@link ResourceBundleControlProvider} are ignored in
* named modules.
* </li>
* </ul>
*
@ -264,17 +261,6 @@ import static sun.security.util.SecurityConstants.GET_CLASSLOADER_PERMISSION;
* {@link #getBundle(String, Locale, ClassLoader, Control) getBundle}
* factory method for details.
*
* <p><a name="modify_default_behavior">For the {@code getBundle} factory</a>
* methods that take no {@link Control} instance, their <a
* href="#default_behavior"> default behavior</a> of resource bundle loading
* can be modified with <em>installed</em> {@link
* ResourceBundleControlProvider} implementations. Any installed providers are
* detected at the {@code ResourceBundle} class loading time. If any of the
* providers provides a {@link Control} for the given base name, that {@link
* Control} will be used instead of the default {@link Control}. If there is
* more than one service provider installed for supporting the same base name,
* the first one returned from {@link ServiceLoader} will be used.
*
* <h3>Cache Management</h3>
*
* Resource bundle instances created by the <code>getBundle</code> factory
@ -469,21 +455,6 @@ public abstract class ResourceBundle {
*/
private volatile Set<String> keySet;
private static final List<ResourceBundleControlProvider> providers;
static {
List<ResourceBundleControlProvider> list = null;
ServiceLoader<ResourceBundleControlProvider> serviceLoaders
= ServiceLoader.loadInstalled(ResourceBundleControlProvider.class);
for (ResourceBundleControlProvider provider : serviceLoaders) {
if (list == null) {
list = new ArrayList<>();
}
list.add(provider);
}
providers = list;
}
/**
* Sole constructor. (For invocation by subclass constructors, typically
* implicit.)
@ -948,7 +919,7 @@ public abstract class ResourceBundle {
{
Class<?> caller = Reflection.getCallerClass();
return getBundleImpl(baseName, Locale.getDefault(),
caller, getDefaultControl(caller, baseName));
caller, Control.INSTANCE);
}
/**
@ -1022,7 +993,7 @@ public abstract class ResourceBundle {
{
Class<?> caller = Reflection.getCallerClass();
return getBundleImpl(baseName, locale,
caller, getDefaultControl(caller, baseName));
caller, Control.INSTANCE);
}
/**
@ -1163,10 +1134,7 @@ public abstract class ResourceBundle {
*
* <p>This method behaves the same as calling
* {@link #getBundle(String, Locale, ClassLoader, Control)} passing a
* default instance of {@link Control} unless another {@link Control} is
* provided with the {@link ResourceBundleControlProvider} SPI. Refer to the
* description of <a href="#modify_default_behavior">modifying the default
* behavior</a>.
* default instance of {@link Control}.
*
* <p><a name="default_behavior">The following describes the default
* behavior</a>.
@ -1364,7 +1332,7 @@ public abstract class ResourceBundle {
throw new NullPointerException();
}
Class<?> caller = Reflection.getCallerClass();
return getBundleImpl(baseName, locale, caller, loader, getDefaultControl(caller, baseName));
return getBundleImpl(baseName, locale, caller, loader, Control.INSTANCE);
}
/**
@ -1589,18 +1557,6 @@ public abstract class ResourceBundle {
return getBundleImpl(baseName, targetLocale, caller, loader, control);
}
private static Control getDefaultControl(Class<?> caller, String baseName) {
if (providers != null && !caller.getModule().isNamed()) {
for (ResourceBundleControlProvider provider : providers) {
Control control = provider.getControl(baseName);
if (control != null) {
return control;
}
}
}
return Control.INSTANCE;
}
private static void checkNamedModule(Class<?> caller) {
if (caller.getModule().isNamed()) {
throw new UnsupportedOperationException(
@ -2573,8 +2529,7 @@ public abstract class ResourceBundle {
* @apiNote <a name="note">{@code ResourceBundle.Control} is not supported
* in named modules.</a> If the {@code ResourceBundle.getBundle} method with
* a {@code ResourceBundle.Control} is called in a named module, the method
* will throw an {@link UnsupportedOperationException}. Any service providers
* of {@link ResourceBundleControlProvider} are ignored in named modules.
* will throw an {@link UnsupportedOperationException}.
*
* @since 1.6
* @see java.util.spi.ResourceBundleProvider

View File

@ -35,21 +35,19 @@ import java.util.ResourceBundle;
* no {@link java.util.ResourceBundle.Control} instance can be modified with {@code
* ResourceBundleControlProvider} implementations.
*
* <p>Provider implementations must be packaged using the <a
* href="../../../../technotes/guides/extensions/index.html">Java Extension
* Mechanism</a> as installed extensions. Refer to {@link java.util.ServiceLoader}
* for the extension packaging. Any installed {@code
* ResourceBundleControlProvider} implementations are loaded using {@link
* java.util.ServiceLoader} at the {@code ResourceBundle} class loading time.
*
* <p>All {@code ResourceBundleControlProvider}s are ignored in named modules.
*
* @author Masayoshi Okutsu
* @since 1.8
* @see ResourceBundle#getBundle(String, java.util.Locale, ClassLoader, ResourceBundle.Control)
* ResourceBundle.getBundle
* @see java.util.ServiceLoader#loadInstalled(Class)
* @deprecated There is no longer any mechanism to install a custom
* {@code ResourceBundleControlProvider} implementation defined
* by the platform class loader or its ancestor. The recommended
* way to use a custom {@code Control} implementation to load resource bundle
* is to use {@link java.util.ResourceBundle#getBundle(String, Control)}
* or other factory methods that take custom {@link java.util.ResourceBundle.Control}.
*/
@Deprecated(since="9", forRemoval=true)
public interface ResourceBundleControlProvider {
/**
* Returns a {@code ResourceBundle.Control} instance that is used

View File

@ -292,8 +292,6 @@ com/sun/jdi/sde/SourceDebugExtensionTest.java 8158066 windows-
# jdk_util
java/util/spi/ResourceBundleControlProvider/UserDefaultControlTest.java 8062512 generic-all
java/util/BitSet/BitSetStreamTest.java 8079538 generic-all

View File

@ -1,59 +0,0 @@
/*
* Copyright (c) 2012, 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.
*
* 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 6959653
* @summary Test ResourceBundle.Control provided using SPI.
* @build UserDefaultControlTest
* @run shell UserDefaultControlTest.sh
*/
import java.io.*;
import java.net.*;
import java.util.*;
public class UserDefaultControlTest {
public static void main(String[] args) {
ResourceBundle rb = ResourceBundle.getBundle("com.foo.XmlRB", Locale.ROOT);
String type = rb.getString("type");
if (!type.equals("XML")) {
throw new RuntimeException("Root Locale: type: got " + type
+ ", expected XML (ASCII)");
}
rb = ResourceBundle.getBundle("com.foo.XmlRB", Locale.JAPAN);
type = rb.getString("type");
// Expect fullwidth "XML"
if (!type.equals("\uff38\uff2d\uff2c")) {
throw new RuntimeException("Locale.JAPAN: type: got " + type
+ ", expected \uff38\uff2d\uff2c (fullwidth XML)");
}
try {
rb = ResourceBundle.getBundle("com.bar.XmlRB", Locale.JAPAN);
throw new RuntimeException("com.bar.XmlRB test failed.");
} catch (MissingResourceException e) {
// OK
}
}
}

View File

@ -1,25 +0,0 @@
#
# Copyright (c) 2012, 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.
#
# 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.
#
${TESTJAVA}/bin/java ${TESTVMOPTS} -Djava.ext.dirs=${TESTSRC} -cp ${TESTCLASSES} UserDefaultControlTest

View File

@ -1,63 +0,0 @@
#
# Copyright (c) 2012, 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.
#
#
# Makefile for building a ResourceBundleControlProvider jar file for testing.
#
# Usage: make JDK_HOME=... all install
#
DESTDIR = ..
TMPDIR = tmp
SERVICESDIR = $(TMPDIR)/META-INF/services
TARGETJAR = rbcontrolprovider.jar
BINDIR = $(JDK_HOME)/bin
all: $(TARGETJAR)
install: all
cp $(TARGETJAR) $(DESTDIR)
SERVICES = java.util.spi.ResourceBundleControlProvider
FILES_JAVA = UserControlProvider.java \
UserXMLControl.java
RESOURCE_FILES = XmlRB.xml \
XmlRB_ja.xml
$(TARGETJAR): $(SERVICES) $(FILES_JAVA) $(RESOURCE_FILES)
rm -rf $(TMPDIR) $@
mkdir -p $(SERVICESDIR)
$(BINDIR)/javac -d $(TMPDIR) $(FILES_JAVA)
cp $(SERVICES) $(SERVICESDIR)
cp $(RESOURCE_FILES) $(TMPDIR)/com/foo
$(BINDIR)/jar cvf $@ -C $(TMPDIR) .
clean:
rm -rf $(TMPDIR) $(TARGETJAR)
.PHONY: all install clean

View File

@ -1,43 +0,0 @@
/*
* Copyright (c) 2012, 2013, 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.
*
* 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.
*/
package com.foo;
import java.util.ResourceBundle;
import java.util.spi.ResourceBundleControlProvider;
public class UserControlProvider implements ResourceBundleControlProvider {
static final ResourceBundle.Control XMLCONTROL = new UserXMLControl();
public ResourceBundle.Control getControl(String baseName) {
System.out.println(getClass().getName()+".getControl called for " + baseName);
// Throws a NPE if baseName is null.
if (baseName.startsWith("com.foo.Xml")) {
System.out.println("\treturns " + XMLCONTROL);
return XMLCONTROL;
}
System.out.println("\treturns null");
return null;
}
}

View File

@ -1,95 +0,0 @@
/*
* Copyright (c) 2012, 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.
*
* 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.
*/
package com.foo;
import java.io.*;
import java.net.*;
import java.util.*;
import static java.util.ResourceBundle.Control.*;
public class UserXMLControl extends ResourceBundle.Control {
@Override
public List<String> getFormats(String baseName) {
if (baseName == null) {
throw new NullPointerException();
}
return Arrays.asList("xml");
}
@Override
public ResourceBundle newBundle(String baseName, Locale locale,
String format,
ClassLoader loader,
boolean reload)
throws IllegalAccessException,
InstantiationException, IOException {
if (baseName == null || locale == null
|| format == null || loader == null) {
throw new NullPointerException();
}
ResourceBundle bundle = null;
if (format.equals("xml")) {
String bundleName = toBundleName(baseName, locale);
String resourceName = toResourceName(bundleName, format);
URL url = loader.getResource(resourceName);
if (url != null) {
URLConnection connection = url.openConnection();
if (connection != null) {
if (reload) {
// disable caches if reloading
connection.setUseCaches(false);
}
try (InputStream stream = connection.getInputStream()) {
if (stream != null) {
BufferedInputStream bis = new BufferedInputStream(stream);
bundle = new XMLResourceBundle(bis);
}
}
}
}
}
return bundle;
}
private static class XMLResourceBundle extends ResourceBundle {
private Properties props;
XMLResourceBundle(InputStream stream) throws IOException {
props = new Properties();
props.loadFromXML(stream);
}
protected Object handleGetObject(String key) {
if (key == null) {
throw new NullPointerException();
}
return props.get(key);
}
public Enumeration<String> getKeys() {
// Not implemented
return null;
}
}
}

View File

@ -1,40 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2012, 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.
-->
<!---->
<!-- DTD for properties -->
<!DOCTYPE properties [
<!ELEMENT properties ( comment?, entry* ) >
<!ATTLIST properties version CDATA #FIXED "1.0">
<!ELEMENT comment (#PCDATA) >
<!ELEMENT entry (#PCDATA) >
<!ATTLIST entry key CDATA #REQUIRED>
]>
<properties>
<comment>Test data for UserDefaultControlTest.java</comment>
<entry key="type">XML</entry>
</properties>

View File

@ -1,40 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2012, 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.
-->
<!---->
<!-- DTD for properties -->
<!DOCTYPE properties [
<!ELEMENT properties ( comment?, entry* ) >
<!ATTLIST properties version CDATA #FIXED "1.0">
<!ELEMENT comment (#PCDATA) >
<!ELEMENT entry (#PCDATA) >
<!ATTLIST entry key CDATA #REQUIRED>
]>
<properties>
<comment>Test data for UserDefaultControlTest.java</comment>
<entry key="type"></entry>
</properties>