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

Inconsistent default locale in string formatter methods

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b122
    • CPU:
      x86_64
    • OS:
      windows_7
    • Verification:
      Verified

      Description

      FULL PRODUCT VERSION :


      A DESCRIPTION OF THE PROBLEM :
      String formatter methods in different classes in java.lang, java.util, and java.io packages behave differently when
      (a) Locale.getDefault() and
      (b) Locale.getDefault(Locale.Category.FORMAT)
      differ.

      java.util.Formatter uses (b) by default, which seems to be correct. However, java.lang.String and java.io.PrintStream use Formatter differently in their format(String format, Object... args) methods.

      1. In String class, the default constructor of Formatter is applied, so (b) is used, but the API doc of String.format() incorrectly states that (a) is used.

      2. In PrintStream class, however, (a) is used and the API doc also says that (a) is used.

      As a consequence, these methods may behave differently. I think, they all should use (b) and all API docs should be adjusted.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Execute the following code snippet.

          Locale.setDefault(Locale.ENGLISH);
          Locale.setDefault(Category.FORMAT, Locale.FRENCH);
          System.out.print(String.format("%f\n", 3.14));
          System.out.printf("%f\n", 3.14);


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      3,140000
      3,140000

      ACTUAL -
      3,140000
      3.140000


      REPRODUCIBILITY :
      This bug can be reproduced always.

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                Created:
                Updated:
                Resolved: