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

Error formatting integer values with MessageFormat.format() using HOST provider

    XMLWordPrintable

Details

    • b23
    • x86_64
    • windows_10

    Description

      A DESCRIPTION OF THE PROBLEM :
      Since we are using the locale provider "HOST" (setting the system property "java.locale.providers"), we do have a problem with "MessageFormat.format()" when passing integer (or long) values as parameters.
      Running the program on a windows client (Windows 10 with german locale) formats the integer with 2 decimal places, e.g. "10,00" for integer "10".
      So MessageFormat.format("Page {0} of {1}", 12, 100); produces "Page 12,00 of 100,00" instead of "Page 12 of 100".

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the java main (source code see below) under a windows 10 client.

      Debugging the code shows the following:
      The MessageFormat.format() uses NumberFormat.getInstance(locale) to create a format for numbers - for all kinds of numbers (double, integer, ...). NumberFormat call the getNumberInstance method of the locale provider. The HostLocaleProviderAdapterImpl returns a format with "#,##0.00;-#,##0.00" as pattern which is the reason for the unnecessary two digital places.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      With german windows 10 locale:
      Page 12 of 100
      ACTUAL -
      With german windows 10 locale:
      Page 12,00 of 100,00

      ---------- BEGIN SOURCE ----------
      import java.text.MessageFormat;

      public class Main {

          public static void main(String[] args) {

              System.setProperty("java.locale.providers", "HOST,COMPAT,SPI");

              System.out.println(MessageFormat.format("Page {0} of {1}", 12, 100));
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Formatting the integer as a string and pass this string as a parameter is a workaround for a direct call of MessageFormat.format() in our code, but doesn't help if e.g. a lib uses MessageFormat.format() with integer values.

      FREQUENCY : always


      Attachments

        Issue Links

          Activity

            People

              naoto Naoto Sato
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: