You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by "Brian Minchau (JIRA)" <xa...@xml.apache.org> on 2004/11/16 21:18:25 UTC

[jira] Updated: (XALANJ-1993) proposed fix to ClassCastException in org.apache.xml.res.XMLMessages

     [ http://nagoya.apache.org/jira/browse/XALANJ-1993?page=history ]

Brian Minchau updated XALANJ-1993:
----------------------------------

    Component: Diagnostic-messages-resources

> proposed fix to ClassCastException in org.apache.xml.res.XMLMessages
> --------------------------------------------------------------------
>
>          Key: XALANJ-1993
>          URL: http://nagoya.apache.org/jira/browse/XALANJ-1993
>      Project: XalanJ2
>         Type: Bug
>   Components: Diagnostic-messages-resources
>  Environment: ibm jdk 1.3 and 1.4
>     Reporter: Carlo Marchiori

>
> IBM jdks do not implements correctly the contract of the method java.util.ResourceBundle.getBundle (). In fact they search for a property file implementation of the bundle before the list implementation. 
> The result is that a ClassCastException happens in the class org.apache.xml.res.XMLMessages, specifically in the method
> -------------------------------------
>   public static ListResourceBundle loadResourceBundle(String className)
>           throws MissingResourceException
>   {    
>     Locale locale = Locale.getDefault();
>     try
>     {
>          return (ListResourceBundle)ResourceBundle.getBundle(className, locale);
> -------------------------------------
> I propose that xalan recognises this problem and so adopts a workaround in the source tree. My workaround first checks if the bundle loaded is a ListResourceBundle; if not it wraps it with an adapter.
> -----------------------------------------------------------------
>         //return (ListResourceBundle)ResourceBundle.getBundle(className, locale);
> 	ResourceBundle bundle = ResourceBundle.getBundle(className, locale);
> 	if (bundle instanceof PropertyResourceBundle)
> 	{
> 		return new ListResourceBundleAdapter (bundle);
> 	}
> 	else
> 	{
> 		return (ListResourceBundle) bundle;
> 	}
> ----------------------------------------------------------------------
> My adapter implementation is 
> --------------------------------------------------------------------------
> public class ListResourceBundleAdapter extends ListResourceBundle
> {
> 	Object [][] contents;
> 	
> 	public ListResourceBundleAdapter (ResourceBundle bundle)
> 	{
> 		Enumeration keys = bundle.getKeys();
> 		LinkedList list = new LinkedList ();
> 		
> 		while (keys.hasMoreElements())
> 		{
> 			String key = (String) keys.nextElement();
> 			Object value = bundle.getObject(key);
> 			Object [] pair = new Object [] {key, value};
> 			list.add(pair);			
> 		}
> 		
> 		contents = (Object [][]) list.toArray(new Object [list.size()] []);
> 	}
> 	/* (non-Javadoc)
> 	 * @see java.util.ListResourceBundle#getContents()
> 	 */
> 	protected Object[][] getContents()
> 	{
> 		return contents;
> 	}
> }
> --------------------------------------------------------------------------

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://nagoya.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira


---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-dev-help@xml.apache.org