-
Enhancement
-
Resolution: Duplicate
-
P4
-
None
-
1.4.2
-
x86, sparc
-
solaris_7, windows_xp
Name: js151677 Date: 09/27/2004
FULL PRODUCT VERSION :
jdk 1.4.2
A DESCRIPTION OF THE PROBLEM :
MissingResourceException thrown by the ResourceBundle class can be misleading.
The MissingResourceException is thrown by the
"getBundleImpl(String baseName, Locale locale,ClassLoader loader)"
and propagates to the to
"getBundle(String baseName, Locale locale,ClassLoader loader)"
and then propagates till our code when we call "getBundle()".
Now, "getBundleImpl()", throws MissingResourceException for any exception that occurs, and, not all exception occur due to the Resource file missing.
For example: In my resource file if I have a "\u" not followed any unicode, the "ResourceCacheKey" will get an exception while creating key value pairs. This exception will propagate till "getBundleImpl" which in turn will throw a MissingResourceException even though the Resource exists.
This can be very misleading and results in us trying to figure out if there is something wrong with our package or the classpath etc.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create a resource file.
Have a key value pair in it with '\u' not followed by a unicode.
Ex:
FILE=more\unwanted
(Note the \u in more '\u' nwanted)
Now try to create a bundle with this resource file.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "main" java.util.MissingResourceException: Can't find bundle for base name Test, locale en_US
at java.util.ResourceBundle.throwMissingResourceException(Unknown Source)
at java.util.ResourceBundle.getBundleImpl(Unknown Source)
at java.util.ResourceBundle.getBundle(Unknown Source)
at Test.getMyBundle(Test.java:14)
at Test.main(Test.java:20)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.util.ResourceBundle;
import java.util.Locale;
public class Test{
public void Test(){
}
public ResourceBundle getMyBundle(){
Locale someLocale = new Locale("en", "US");
ResourceBundle rb = ResourceBundle.getBundle("Test",someLocale);
return rb;
}
static public void main(String[] args) {
Test test = new Test();
ResourceBundle mrb = test.getMyBundle();
}
}
---------- END SOURCE ----------
(Incident Review ID: 311744)
======================================================================
- duplicates
-
JDK-4354216 (rb) ResourceBundle and MissingResourceException should support 'cause'
-
- Resolved
-