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

java.util.Locale backward compatibility break

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 7
    • core-libs

      FULL PRODUCT VERSION :
      Java 7, update 1, update 2

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      The introduction in Java 7 of Locale.Category has led to a serious backward compatibility problem.

      I have an US English license of Windows XP running on my system, regionally configured as Italian (Switzerland).

      With Java <= 1.6, System.out.println(Locale.getDefault()) gives "it_CH", which is correct.

      Now Java 1.7 for the same command gives "en_US"; the same happens with System.out.println(Locale.getDefault(Locale.Category.DISPLAY))
      (which I assume is the default value when calling the plain getDefault() method), while System.out.println(Locale.getDefault(Locale.Category.FORMAT))
      produces "it_CH".

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Invoke

      System.out.println(java.util.Locale.getDefault());

      on two systems, one running Java 6 (or older) and the other running Java 7

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      java.util.Locale.getDefault() should return the regionally configured locale
      ACTUAL -
      java.util.Locale.getDefault() returns the system's locale, regardless of the regional settings

      REPRODUCIBILITY :
      This bug can be reproduced always.

      CUSTOMER SUBMITTED WORKAROUND :
      Add code to my localized programs in order to determine the correct locale to use in a mixed java versions scenario, compile them with javac 1.7 with the -source and -target flags set to 1.6 (and tolerate the compiler warnings); something like:

      Locale localeToUse;

      if (System.getProperty("java.runtime.version").startsWith("1.7")) {
          localeToUse = Locale.getDefault(Locale.Category.FORMAT);
      } else {
          localeToUse = Locale.getDefault();
      }

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: