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

(rb) Unexpected behavior of ResourceBundle fallback mechanism

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P4
    • None
    • 5.0
    • core-libs

    Description

      FULL PRODUCT VERSION :
      java version "1.5.0_07"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_07-b03)
      Java HotSpot(TM) Client VM (build 1.5.0_07-b03, mixed mode, sharing)

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

      A DESCRIPTION OF THE PROBLEM :
      The fallback mechanism of ResourceBundle depends on default locale (Locale.getDefault()) in an unexpected way.

      Assume we have .properties localization files for different languages, with the root language, which is as a matter of fact English. For instance, we have root property file i18n.properties with English stuff, and then i18n_cs.properties with Czech stuff. If we call ResourceBundle.getBundle for czech locale, we get stuff from i18n_cs if we call it for english locale, or any other locale, we should get the fallback stuff from the root i18n file, regardless what Locale.getDefault says. That is, if the developer decided that the root locale is English, it should be English even on systems that have set locale to e.g. czech.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      see example code. you also need to create the two property files in the same dir as the .java file:
      - i18n.properties ----
      key=Key
      - i18n_cs.properties ----
      key=Klic


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      the test case should return "Key", because we are asking for bundle that is not supported (English), so we should fall back to the superordinate root bundle
      ACTUAL -
      the test case actually returns "Klic", i.e. the fallback mechanism falls back to bundle of the system's default locale, not to the superordinate bundle of the requested English bundle.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package org.ksmsa.utils.i18n.test;

      import java.util.Locale;
      import java.util.ResourceBundle;

      public class ResourceBundleTest {

      public static void main(String[] args) {
      Locale.setDefault(new Locale("cs"));
      ResourceBundle bundle = ResourceBundle.getBundle(
      "org.ksmsa.utils.i18n.test.i18n", Locale.ENGLISH);
      System.out.println(bundle.getString("key"));
      }

      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      for each root .properties resource bundle, create its copy named according to its language. In our case, for each i18n.properties create a copy named i18n_en.properties

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              ndcosta Nelson Dcosta (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: