< prev index next >

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

Print this page
rev 59397 : imported patch 8245241

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2012, 2019, 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

@@ -24,12 +24,12 @@
  */
 
 package sun.util.locale.provider;
 
 import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
 import java.text.DecimalFormat;
+import java.util.ServiceConfigurationError;
 import java.util.spi.LocaleServiceProvider;
 
 /**
  * LocaleProviderAdapter implementation for the host locale data.
  * Currently it is only implemented on Windows Vista or later.

@@ -48,20 +48,24 @@
 
     @Override
     @SuppressWarnings("unchecked")
     protected <P extends LocaleServiceProvider> P findInstalledProvider(final Class<P> c) {
         try {
-            Method getter = HostLocaleProviderAdapterImpl.class.getMethod(
-                    "get" + c.getSimpleName(), (Class<?>[]) null);
-            return (P)getter.invoke(null, (Object[]) null);
-        }  catch (NoSuchMethodException |
-                  IllegalAccessException |
+            return (P)Class.forName(
+                        "sun.util.locale.provider.HostLocaleProviderAdapterImpl")
+                    .getMethod("get" + c.getSimpleName(), (Class<?>[]) null)
+                    .invoke(null, (Object[]) null);
+        } catch (ClassNotFoundException |
+                 NoSuchMethodException ex) {
+            // permissible exceptions as platform may not support host adapter
+            return null;
+        } catch (IllegalAccessException |
                   IllegalArgumentException |
                   InvocationTargetException ex) {
-            LocaleServiceProviderPool.config(HostLocaleProviderAdapter.class, ex.toString());
+            throw new ServiceConfigurationError(
+                "Host locale provider cannot be located.", ex);
         }
-        return null;
     }
 
     /**
      * Utility to make the decimal format specific to integer, called
      * by the platform dependent adapter implementations.
< prev index next >