< prev index next >

src/java.base/share/classes/sun/util/locale/provider/LocaleProviderAdapter.java

Print this page
rev 59374 : [mq]: 8245241

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2020, 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

@@ -48,36 +48,38 @@
 import java.util.spi.TimeZoneNameProvider;
 import sun.security.action.GetPropertyAction;
 import sun.text.spi.JavaTimeDateTimePatternProvider;
 import sun.util.spi.CalendarProvider;
 
+import static java.lang.System.*;
+
 /**
  * The LocaleProviderAdapter abstract class.
  *
  * @author Naoto Sato
  * @author Masayoshi Okutsu
  */
 public abstract class LocaleProviderAdapter {
     /**
      * Adapter type.
      */
-    public static enum Type {
+    public enum Type {
         JRE("sun.util.locale.provider.JRELocaleProviderAdapter", "sun.util.resources", "sun.text.resources"),
         CLDR("sun.util.cldr.CLDRLocaleProviderAdapter", "sun.util.resources.cldr", "sun.text.resources.cldr"),
         SPI("sun.util.locale.provider.SPILocaleProviderAdapter"),
         HOST("sun.util.locale.provider.HostLocaleProviderAdapter"),
         FALLBACK("sun.util.locale.provider.FallbackLocaleProviderAdapter", "sun.util.resources", "sun.text.resources");
 
         private final String CLASSNAME;
         private final String UTIL_RESOURCES_PACKAGE;
         private final String TEXT_RESOURCES_PACKAGE;
 
-        private Type(String className) {
+        Type(String className) {
             this(className, null, null);
         }
 
-        private Type(String className, String util, String text) {
+        Type(String className, String util, String text) {
             CLASSNAME = className;
             UTIL_RESOURCES_PACKAGE = util;
             TEXT_RESOURCES_PACKAGE = text;
         }
 

@@ -111,16 +113,17 @@
     static volatile LocaleProviderAdapter.Type defaultLocaleProviderAdapter;
 
     /**
      * Adapter lookup cache.
      */
-    private static ConcurrentMap<Class<? extends LocaleServiceProvider>, ConcurrentMap<Locale, LocaleProviderAdapter>>
+    private static final ConcurrentMap<Class<? extends LocaleServiceProvider>, ConcurrentMap<Locale, LocaleProviderAdapter>>
         adapterCache = new ConcurrentHashMap<>();
 
     static {
         String order = GetPropertyAction.privilegedGetProperty("java.locale.providers");
-        List<Type> typeList = new ArrayList<>();
+        ArrayList<Type> typeList = new ArrayList<>();
+        String invalidTypeMessage = null;
 
         // Check user specified adapter preference
         if (order != null && !order.isEmpty()) {
             String[] types = order.split(",");
             for (String type : types) {

@@ -131,32 +134,40 @@
                 try {
                     Type aType = Type.valueOf(type.trim().toUpperCase(Locale.ROOT));
                     if (!typeList.contains(aType)) {
                         typeList.add(aType);
                     }
-                } catch (IllegalArgumentException | UnsupportedOperationException e) {
-                    // could be caused by the user specifying wrong
-                    // provider name or format in the system property
-                    LocaleServiceProviderPool.config(LocaleProviderAdapter.class, e.toString());
+                } catch (IllegalArgumentException e) {
+                    // construct a log message.
+                    invalidTypeMessage = "Invalid locale provider adapter \"" + type + "\" ignored.";
                 }
             }
         }
 
         defaultLocaleProviderAdapter = Type.CLDR;
         if (!typeList.isEmpty()) {
             // bona fide preference exists
-            if (!(typeList.contains(Type.CLDR) || (typeList.contains(Type.JRE)))) {
+            if (!(typeList.contains(Type.CLDR) || typeList.contains(Type.JRE))) {
                 // Append FALLBACK as the last resort when no ResourceBundleBasedAdapter is available.
                 typeList.add(Type.FALLBACK);
                 defaultLocaleProviderAdapter = Type.FALLBACK;
             }
         } else {
             // Default preference list.
             typeList.add(Type.CLDR);
             typeList.add(Type.JRE);
         }
         adapterPreference = Collections.unmodifiableList(typeList);
+
+        // Emit logs, if any, after 'adapterPreference' is initialized which is needed
+        // for logging.
+        if (invalidTypeMessage != null) {
+            // could be caused by the user specifying wrong
+            // provider name or format in the system property
+            getLogger(LocaleProviderAdapter.class.getCanonicalName())
+                .log(Logger.Level.INFO, invalidTypeMessage);
+        }
     }
 
     /**
      * Returns the singleton instance for each adapter type
      */

@@ -181,11 +192,12 @@
                     }
                 } catch (ClassNotFoundException |
                          IllegalAccessException |
                          InstantiationException |
                          UnsupportedOperationException e) {
-                    LocaleServiceProviderPool.config(LocaleProviderAdapter.class, e.toString());
+                    getLogger(LocaleProviderAdapter.class.getCanonicalName())
+                            .log(Logger.Level.INFO, e);
                     adapterInstances.putIfAbsent(type, NONEXISTENT_ADAPTER);
                     if (defaultLocaleProviderAdapter == type) {
                         defaultLocaleProviderAdapter = Type.FALLBACK;
                     }
                 }
< prev index next >