BUG: Cannot Access Properties File with ResourceBundle (327329)
The information in this article applies to:
- Microsoft Visual J# .NET (2002)
This article was previously published under Q327329 SYMPTOMS When you use the getBundle method from java.util.ResourceBundle to access a properties file, you may receive the following
exception error message: An unhandled exception of type
'java.util.MissingResourceException' occurred in vjslib.dll
CAUSE This is a bug in ResourceBundle when it tries to load the resources. The calling assembly name is
being passed incorrectly. RESOLUTIONThere are two possible workarounds for this problem.
- Use the PropertyResourceBundle class to manage the resources. PropertyResourceBundle requires an InputStream. Therefore, for localized resources, you must calculate the
localized name of the resource. For example, replace the code
String name = "MyResources";
ResourceBundle propertyBundle = ResourceBundle.getBundle(name, locale); with the following:String name = "MyResources";
if (!Locale.ENGLISH.equals(locale)) name += "_" + locale;
// Load resource as inputStream.
java.io.InputStream is = testProperties.class.getResourceAsStream(name+".properties");
// Construct PropertyResourceBundle
PropertyResourceBundle propertyBundle = new PropertyResourceBundle(is);
// Here, if you give a ResourceBundle Object, you cannot gain access to the handleGetObject method
// because it is protected in ResourceBundle while it is public in PropertyResourceBundle.
// You must have access to this method. - Provide a ResourceBundle subclass that manages your resources. Instead of using an
external property file, create a class that inherits from ResourceBundle. The following subclass example contains the bundle named MyResources. For localized resources, there are additional subclasses that
are named by using the extension of the locale. For example, the German
subclass is named MyResources_de.
public class MyResources extends ResourceBundle
{
public Object handleGetObject(String key)
{
if (key.equals("s1")) return "String1";
if (key.equals("s2")) return "String2";
return null;
}
}
STATUSMicrosoft has confirmed that this is a bug in the Microsoft
products that are listed at the beginning of this article.
MORE INFORMATION Note that in the first workaround, you also do not see a
fallback behavior to a default locale if the properties file does not exist.
You must add custom handler code for a default resource file if there is a
possibility that the desired locale-specific properties file does not exist.
REFERENCES For more information about Java language support on
Microsoft .NET, visit the following Microsoft Developer Network (MSDN) Web
site: The Vjsresgen sample is located in the MSDN product documentation
in the following folder: Visual J#\Visual J# Samples\Application Samples\Vjsresgen Sample
Modification Type: | Major | Last Reviewed: | 1/19/2004 |
---|
Keywords: | kbbug kbpending KB327329 |
---|
|