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

ResourceBundle.getBundle function broken

    XMLWordPrintable

Details

    Description



      Name: rm29839 Date: 10/27/97


      Given the following code in a directory called com:

      package com;

      public class loc {
          public loc() {}

          public java.lang.String toString () {
              java.util.ResourceBundle b = java.util.ResourceBundle.getBundle(
                  "com.loc", java.util.Locale.getDefault());

              java.lang.String label;

              try {
                  label = b.getString("Warning");
              } catch (java.util.MissingResourceException e) {
                  label = "problem";
              }
              return label;
          }
      }

      With the following properties files:

      loc.properties:
      Warning=Warning

      loc_en_US_TX.properties:
      Warning=Warnin'

      In the parent directory of the above mentioned is a test program
      test.java:

      import java.util.*;
      import java.lang.*;
      import java.io.*;

      public class test {

              private static void getProperties() {
                      String propsfilename = "myprops";
                      Properties props = new Properties(System.getProperties());
                      try {
                              props.load(new BufferedInputStream(new FileInputStream(p
      ropsfilename)));
                      } catch (IOException e) {}
                      System.setProperties (props);

              Locale.setDefault(new Locale(props.getProperty("test.language"),
                                           props.getProperty("test.country"),
                                           props.getProperty("test.variant")));
             }

              public static void main(String[] args) {
                      getProperties();
                      com.loc a = new com.loc();
                      System.out.println(a.toString());
              }
      }

      With the following system properties file:

      myprops:
      test.language=en
      test.country=US
      test.variant=TX

      Running the above programs produces the following errors:

      java.lang.ClassCastException: com.loc
              at java.util.ResourceBundle.findBundle(ResourceBundle.java)
              at java.util.ResourceBundle.getBundle(ResourceBundle.java)
              at java.util.ResourceBundle.getBundle(ResourceBundle.java)
              at com.loc.toString(Compiled Code)
              at test.main(Compiled Code)

      If, however, I change the 1st parameter of getBundle in loc.java to "loc"
      instead of "com.loc", I get the following error output:

      java.util.MissingResourceException: can't find resource for loc_en_US_TX
              at java.util.ResourceBundle.getBundle(ResourceBundle.java)
              at java.util.ResourceBundle.getBundle(ResourceBundle.java)
              at com.loc.toString(Compiled Code)
              at test.main(Compiled Code)

      Additionally, if the loc*.properties files are moved to the same
      directory as test.java, the program works correctly.

      It seems that there is a problem with the resolution of the basename in
      the first parameter of the getBundle() methdod.

      There is no posting of this problem in the known bug list on java.sun.com.
      There are some postings of similar problems on comp.lang.java.* but no
      solutions/workarounds.

      If possible, I would like an update on solutions or workarounds.
      test.variant=TX

      Running the above programs produces the following errors:


      With 2 properties files:

      company - Hitachi Telecom , email - ###@###.###
      ======================================================================

      Attachments

        Issue Links

          Activity

            People

              rgillamsunw Richard Gillam (Inactive)
              rmandelsunw Ronan Mandel (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: