提交 ccf3731f 编写于 作者: S sherman

6514993: (prefs)prefs should use java.util.ServiceLoader to lookup service providers

Reviewed-by: iris
Contributed-by: xueming.shen@sun.com
上级 6b777caf
...@@ -32,9 +32,8 @@ import java.security.AccessController; ...@@ -32,9 +32,8 @@ import java.security.AccessController;
import java.security.Permission; import java.security.Permission;
import java.security.PrivilegedAction; import java.security.PrivilegedAction;
import java.util.Iterator; import java.util.Iterator;
import sun.misc.Service; import java.util.ServiceLoader;
import sun.misc.ServiceConfigurationError; import java.util.ServiceConfigurationError;
// These imports needed only as a workaround for a JavaDoc bug // These imports needed only as a workaround for a JavaDoc bug
import java.lang.RuntimePermission; import java.lang.RuntimePermission;
...@@ -274,12 +273,14 @@ public abstract class Preferences { ...@@ -274,12 +273,14 @@ public abstract class Preferences {
private static PreferencesFactory factory1() { private static PreferencesFactory factory1() {
// 2. Try service provider interface // 2. Try service provider interface
Iterator i = Service.providers(PreferencesFactory.class, Iterator<PreferencesFactory> itr = ServiceLoader
ClassLoader.getSystemClassLoader()); .load(PreferencesFactory.class, ClassLoader.getSystemClassLoader())
.iterator();
// choose first provider instance // choose first provider instance
while (i.hasNext()) { while (itr.hasNext()) {
try { try {
return (PreferencesFactory) i.next(); return itr.next();
} catch (ServiceConfigurationError sce) { } catch (ServiceConfigurationError sce) {
if (sce.getCause() instanceof SecurityException) { if (sce.getCause() instanceof SecurityException) {
// Ignore the security exception, try the next provider // Ignore the security exception, try the next provider
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册