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

Locale.getDefault always returns USA instead of configured country

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 7
    • core-libs

      FULL PRODUCT VERSION :
      java version "1.7.0"
      Java(TM) SE Runtime Environment (build 1.7.0-b147)
      Java HotSpot(TM) 64-Bit Server VM (build 21.0-b17, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Windows 7 [Version 6.1.7601] 64-bit

      A DESCRIPTION OF THE PROBLEM :
      When I configure my country as Canada in the Windows 7 64 bit control panel,
      Locale.getDefault.getCountry reports it as USA, in JDK 1.7. It works fine under
      JDK 1.6. System.getProperty("user.country", "n/a") also reports USA when it should report Canada.

      REGRESSION. Last worked in version 6u26

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      see http://mindprod.com/jgloss/locale.html for a listing of TestLocale.java
      SSCCE

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      see http://mindprod.com/locale.html for a listing of the output/expected output.

      ACTUAL -
      see http://mindprod.com/locale.html for a listing of the output/expected output.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      none. It just reports the wrong country.


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      /*
       * [TestLocale.java]
       *
       * Summary: Get the Locale.
       *
       * Copyright: (c) 2011 Roedy Green, Canadian Mind Products, http://mindprod.com
       *
       * Licence: This software may be copied and used freely for any purpose but military.
       * http://mindprod.com/contact/nonmil.html
       *
       * Requires: JDK 1.7+
       *
       * Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/
       *
       * Version History:
       * 1.0 2011-08-21
       */
      package com.mindprod.example;

      import java.util.Locale;

      import static java.lang.System.out;

      /**
       * Display the Locale
       *
       * @author Roedy Green, Canadian Mind Products
       * @version 1.1 2011-08-23 add Lew Bloch's requested extensions, display of user.country and setDefault.
       * @since 2011-08-21
       */
      public final class TestLocale
          {
          // -------------------------- STATIC METHODS --------------------------

          /**
           * display fields of a Locale
           *
           * @param l the Locale
           * @param desc description of the Locale
           */
          private static void showLocale( String desc, Locale l )
              {
              out.println( desc );
              out.println( "display:" + l.getDisplayName() );
              out.println( "country:" + l.getCountry() );
              out.println( "ISO3:" + l.getISO3Country() );
              out.println( "display country:" + l.getDisplayCountry() );
              out.println( "language:" + l.getLanguage() );
              out.println( "display language:" + l.getDisplayLanguage() );
              out.println( "user.country:" + System.getProperty( "user.country", "n/a" ) );
              out.println( "user.language:" + System.getProperty( "user.language", "n/a" ) );
              out.println();
              }

          // --------------------------- main() method ---------------------------

          /**
           * Display current Locale
           *
           * @param args not used
           */
          public static void main( String[] args )
              {
              // various ways to get a Locale

              // demonstrates bugs in Windows 7 64-bit JDK 1.7 when country is configured in control panel as Canada.
              // user.country reports as US instead of CA
              // Locale.getDefault.getCountry() reports US instead of CA

              Locale defaultLocale = Locale.getDefault(); // browser/JVM default
              showLocale( "D E F A U L T", defaultLocale );

              Locale specifiedLocale = new Locale( "en", "US" ); // language/country
              showLocale( "N E W E N U S", specifiedLocale );

              Locale localeConstant = Locale.CANADA_FRENCH; // static final constants
              showLocale( "C A N A D A _ F R E N C H", localeConstant );

              Locale.setDefault( Locale.CANADA );
              Locale forcedDefault = Locale.getDefault();
              showLocale( "F O R C E D D E F A U L T", forcedDefault );

              // Locale serverLocale = request.getLocale(); // in a servlet to get remote user's locale
              }
          }

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

      CUSTOMER SUBMITTED WORKAROUND :
      User program must explicitly set the locale on every run.

      I use it for example to select the user's preferred currency. They must now manually select it.

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: