Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8227830

NumberStringConverter and its siblings should respect the FORMAT locale

    Details

    • Type: Bug
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 8u60, openjfx12
    • Fix Version/s: tbd
    • Component/s: javafx
    • Labels:
    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      windows_10

      Description

      ADDITIONAL SYSTEM INFORMATION :
      Windows 10, Java 12

      A DESCRIPTION OF THE PROBLEM :
      The default constructor of javafx.util.converter.NumberStringConverter use the default locale returned by Locale.getDefault(). If the format locale (returned by Locale.getDefault(Category.FORMAT)) is different formatting in the application is not consistent as E.g. a default NumberFormat uses the format locale as shown below in the default factory method:

          public final static NumberFormat getNumberInstance() {
              return getInstance(Locale.getDefault(Locale.Category.FORMAT), NUMBERSTYLE);
          }

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Set the format locale different from the default locale:
              Locale.setDefault(Locale.US);
              Locale.setDefault(Category.FORMAT, Locale.GERMANY);
      This will be the case when you have a English language Windows and set the regional formatting settings to something different.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Using a NumberFormat and a NumberStringConverter created with the default factory method/constructor should result in consistent formatting.
      ACTUAL -
      Using a NumberFormat and a NumberStringConverter created with the default factory method/constructor might result in different output for the same value.

      ---------- BEGIN SOURCE ----------
      import java.text.NumberFormat;
      import java.util.Locale;
      import java.util.Locale.Category;

      import javafx.util.converter.DoubleStringConverter;

      public class Test
      {

          public static void main(String[] args)
          {
              Locale.setDefault(Locale.US);
              Locale.setDefault(Category.FORMAT, Locale.GERMANY);

              System.out.println(NumberFormat.getInstance().format(1.234d));
              System.out.println(new DoubleStringConverter().toString(1.234d));
          }

      }

      ---------- END SOURCE ----------

        Attachments

          Activity

            People

            • Assignee:
              kcr Kevin Rushforth
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: