src/java.base/share/classes/java/util/Scanner.java
changeset 48258 1925dbd47e28
parent 48252 77b88d8f8380
child 49285 4d2e3f5abb48
--- a/src/java.base/share/classes/java/util/Scanner.java	Tue Dec 12 20:18:14 2017 -0800
+++ b/src/java.base/share/classes/java/util/Scanner.java	Wed Dec 13 12:43:38 2017 +0530
@@ -33,10 +33,13 @@
 import java.nio.file.Path;
 import java.nio.file.Files;
 import java.text.*;
+import java.text.spi.NumberFormatProvider;
 import java.util.function.Consumer;
 import java.util.regex.*;
 import java.util.stream.Stream;
 import java.util.stream.StreamSupport;
+import sun.util.locale.provider.LocaleProviderAdapter;
+import sun.util.locale.provider.ResourceBundleBasedAdapter;
 
 /**
  * A simple text scanner which can parse primitive types and strings using
@@ -1262,9 +1265,27 @@
 
         modCount++;
         this.locale = locale;
-        DecimalFormat df =
-            (DecimalFormat)NumberFormat.getNumberInstance(locale);
+
+        DecimalFormat df = null;
+        NumberFormat nf = NumberFormat.getNumberInstance(locale);
         DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance(locale);
+        if (nf instanceof DecimalFormat) {
+             df = (DecimalFormat) nf;
+        } else {
+
+            // In case where NumberFormat.getNumberInstance() returns
+            // other instance (non DecimalFormat) based on the provider
+            // used and java.text.spi.NumberFormatProvider implementations,
+            // DecimalFormat constructor is used to obtain the instance
+            LocaleProviderAdapter adapter = LocaleProviderAdapter
+                    .getAdapter(NumberFormatProvider.class, locale);
+            if (!(adapter instanceof ResourceBundleBasedAdapter)) {
+                adapter = LocaleProviderAdapter.getResourceBundleBased();
+            }
+            String[] all = adapter.getLocaleResources(locale)
+                    .getNumberPatterns();
+            df = new DecimalFormat(all[0], dfs);
+        }
 
         // These must be literalized to avoid collision with regex
         // metacharacters such as dot or parenthesis