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

(rb) Clarify ResourceBundle javadocs for implicit inheritance of base bundle

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 1.4.1
    • core-libs
    • Fix Understood
    • x86
    • windows_2000

      Name: nt126004 Date: 05/07/2003


      FULL PRODUCT VERSION :
      java version "1.4.1_02"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_02-b06)
      Java HotSpot(TM) Client VM (build 1.4.1_02-b06, mixed mode)

      FULL OS VERSION :
      Microsoft Windows 2000 [Version 5.00.2195]

      A DESCRIPTION OF THE PROBLEM :
      It appears that an implicit inheritance is set between
      a ResourceBundle for a specific locale, and the 'base'
      ResourceBundle.

      Unfortunately, this is not at all obvious when reading the
      javadocs for ResourceBundle. To the contrary, the javadocs
      show an example where it appears that the inheritance
      must be set explicitely to get that behavior.



         // default (English language, United States)
         public class MyResources extends ResourceBundle {
             public Object handleGetObject(String key) {
      if (key.equals("okKey")) return "Ok";
      if (key.equals("cancelKey")) return "Cancel";
      return null;
             }
         }
        
         // German language
         public class MyResources_de extends MyResources {
             public Object handleGetObject(String key) {
      // don't need okKey, since parent level handles it.
      if (key.equals("cancelKey")) return "Abbrechen";
      return null;
             }
         }
       
      In using the two classes below, it came as a surprise that
      keys not found by the 'it' bundle where retrieved from the
      'base' bundle.


      The API documentation describes how a resource _bundle_ is selected.
      Let's say for example that I have "Resources_de', 'Resources_fr', and 'Resources'.
      If the locale is set to 'fr', I'd get 'Resources_fr'.
      If the locale is set to 'en', I'd get 'Resources'.

      This is fine and well described.

      However, let's say I have locale set to 'fr', and the 'Resources_fr' bundle
      is then selected.

      The following text:

         The family should have a default resource bundle which simply has the same name
         as its family - "MyResources" - and will be used as the bundle of last resort
         if a specific locale is not supported.

      does not apply since my locale has allowed me to get a bundle (Resources_fr).

      It is therefore not clear at all that if a key does not exist in the 'Resources_fr' bundle,
      then it will default to the 'Resources' bundle.

      Moreover, the example in the javadocs seems to imply that 'Resources_fr'
      should inherit from 'Resources' to have that behavior.
      [not clear why in the example the class MyResources_de extends MyResources
      since getting a key from the 'base' bundle (when key not specified in MyResources_de)
      will happen even if MyResources_de does not extend MyResources].

      ----- Resources_it -----------------
      package i18n;
      import java.util.*;
      public class Resources_it extends ListResourceBundle {
          private static Object[][] contents;
          static {
      contents = new Object[][] {
      { "greetingMorning", "Buon giorno!" }
      };
          }
          public Object[][] getContents() {
      return contents;
          }
      }

      ----- Resources -----------------
      package i18n;
      import java.util.*;
      public class Resources extends ListResourceBundle {
          private static Object[][] contents;
          static {
      contents = new Object[][] {
      { "greetingMorning", "Good Morning!" },
      { "greetingEvening", "Good Evening!" },
      };
          }
          public Object[][] getContents() {
      return contents;
          }
      }



      REPRODUCIBILITY :
      This bug can be reproduced always.
      (Review ID: 184865)
      ======================================================================

            naoto Naoto Sato
            nthompsosunw Nathanael Thompson (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: