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

ResourceBundle throws Misleading Exception when \u is used in properties file.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • 6
    • 6
    • core-libs

      Tried on Windows2000 and JDK build 1.6.0-ea-b15

      See the following testcase

      /*
       * TestRes.java
       * author Namita ,Seetharama
       */
      import java.util.*;
      import java.io.*;



      class TestRes{
           public static void main(String args[]) {
               ResourceBundle re = ResourceBundle.getBundle("ASR", Locale.getDefault());
               System.out.println(re.getString("key1"));
               System.out.println(re.getString("key2"));
           }
      }
      Property file used for the above testcase is ASR_en_US.PROPERTIES with data as
      key1=c:\unamita\namita.txt
      key2=c:\namita\namita.txt

      Output:
      Exception in thread "main" java.util.MissingResourceException: Can't find bundle for base name ASR, locale en
              at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:837)
              at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:806)
              at java.util.ResourceBundle.getBundle(ResourceBundle.java:577)
              at TestRes.main(TestRes.java:12)


      This Exception is misleading to the user as resource is in the same directory and available.
      If we remove "key1" from Properties file it executes without exception.

      If the same Property file is used with PropertyResourceBundle class throws different Exception. See the following testcase.

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

      class TestRes1{
          
           public static void main(String args[]) throws Exception {
               
               //ResourceBundle re = ResourceBundle.getBundle("ASR", Locale.getDefault());
               ResourceBundle re = new PropertyResourceBundle(ClassLoader.getSystemClassLoader().getResourceAsStream("ASR_en_US.PROPERTIES"));
               
               System.out.println(re.getString("key1"));
               System.out.println(re.getString("key2"));
           }
      }

      The Output:
      Exception in thread "main" java.lang.IllegalArgumentException: Malformed \uxxxx encoding.
              at java.util.Properties.loadConvert(Properties.java:492)
              at java.util.Properties.load(Properties.java:331)
              at java.util.PropertyResourceBundle.<init>(PropertyResourceBundle.java:96)
              at TestRes1.main(TestRes1.java:11)

      ResourceBundle throws the same exception even when locale is not set properly.

      ###@###.### 2004-12-20 09:34:56 GMT

            okutsu Masayoshi Okutsu
            savadhansunw Seetharama Avadhanam (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: