JDK-4028735 : ResourceBundle may have undocumented feature
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util:i18n
  • Affected Version: 1.1
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_95
  • CPU: x86
  • Submitted: 1997-01-29
  • Updated: 2000-02-19
  • Resolved: 2000-02-19
Related Reports
Duplicate :  
Description

Name: mc57594			Date: 01/29/97


The documentation for ResourceBundle describes in detail
 the class lookup strategy for the getResourceBundle method but
 does not mention that a properties file may be used instead of
 a class and that a PropertyResourceBundle will be returned instead.

 Furthermore, the documentation for PropertyResourceBundle makes
 no mention of this fact and leads the reader to believe that the
 only way of getting a PropertyResourceBundle is to use the constructor.
 Using the constructor means we don't get the benefit of the lookup
 strategy used by getResourceBundle method.

 Assume that we have a properties file called 'resource.properties'
 located in the directory 'sample/package' relative to the current
 directory. Assume also that the current directory is on the CLASSPATH.
 The test application below shows that the call:
  getResourceBundle("sample.package.resource", null)
 finds and loads the properties file and returns a PropertyResourceBundle
 as a result.

 Test application Test2.java:
  import java.util.*;

  public class Test2 {

     public static void main(String args[]) {

        ResourceBundle res =
ResourceBundle.getResourceBundle("sample.package.resource", null);

        System.out.println("Object 'res' is an instance of " +
res.getClass().getName());
        System.out.println("The value of 'string1' in 'res' is '" +
res.getString("string1") + "'");

        System.exit(0);
     }
  }

 Resource file: resource.properties (locate in sample/package directory)
  # resource.properties: sample for class Test2
  string1=Sample string number one.

 Output:
  Object 'res' is an instance of java.util.PropertyResourceBundle
  The value of 'string1' in 'res' is 'Sample string number one.'
======================================================================

Comments
WORK AROUND Name: mc57594 Date: 01/29/97 ======================================================================
11-06-2004

EVALUATION The documentation has been improved over various releases, but a complete fix will be provided under bug 4314141. norbert.lindenberg@Eng 2000-02-18
18-02-2000

SUGGESTED FIX Name: dk30142 Date: 02/09/99 Notice this bug description mistakenly refers to a method named "getResourceBundle()", which is actually named "getBundle()". The point of this bug is that the three methods getBundle() in the ResourceBundle class say only the following: Get the appropriate ResourceBundle subclass. They should instead say something like the following: Get the appropriate ResourceBundle subclass. If this method does not find a class named baseName, it appends ".properties" to baseName and searches for a properties file of that name. If it finds such a file, it creates a new PropertyResourceBundle object to hold it. The following sentences in the class description should also be clarified: The result of the lookup is a class, but that class may be backed by a property file on disk. To this: The result of the lookup is a class, but that class may be backed by a properties file on disk. That is, if getBundle does not find a class of a given name, it appends ".properties" to the class name and searches for a properties file of that name. If it finds such a file, it creates a new PropertyResourceBundle object to hold it. Following on the previous example, it will search for classes and and files as follows: (class) MyResources_fr_CH (file) MyResources_fr_CH.properties (class) MyResources_fr (file) MyResources_fr.properties (class) MyResources_en_US (file) MyResources_en_US.properties (class) MyResources_en (file) MyResources_en.properties (class) MyResources (file) MyResources.properties The PropertyResourceBundle class has already been modified to mention that an instead can be created by using getBundle(). The other questions that dcalhoun raises are appropriate for a more detailed fix, and should be submitted as a separate bug. dkramer@eng 2-9-99 ======================================================================
08-12-0002