You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by "Carlo Marchiori (JIRA)" <xa...@xml.apache.org> on 2004/11/15 15:50:23 UTC

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

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
 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


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

Posted by "Brian Minchau (JIRA)" <xa...@xml.apache.org>.
     [ 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


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

Posted by "Ilene Seelemann (JIRA)" <xa...@xml.apache.org>.
     [ http://issues.apache.org/jira/browse/XALANJ-1993?page=history ]
     
Ilene Seelemann resolved XALANJ-1993:
-------------------------------------

    Resolution: Cannot Reproduce

There haven't been any responses to my comments and I can't reproduce this issue, so I'm marking it resolved.

> proposed fix to ClassCastException in org.apache.xml.res.XMLMessages
> --------------------------------------------------------------------
>
>          Key: XALANJ-1993
>          URL: http://issues.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://issues.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


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

Posted by "Brian Minchau (JIRA)" <xa...@xml.apache.org>.
     [ http://issues.apache.org/jira/browse/XALANJ-1993?page=all ]

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

    Fix Version: 2.7

> proposed fix to ClassCastException in org.apache.xml.res.XMLMessages
> --------------------------------------------------------------------
>
>          Key: XALANJ-1993
>          URL: http://issues.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
>      Fix For: 2.7

>
> 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://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, 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


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

Posted by "Ilene Seelemann (JIRA)" <xa...@xml.apache.org>.
     [ http://issues.apache.org/jira/browse/XALANJ-1993?page=comments#action_57524 ]
     
Ilene Seelemann commented on XALANJ-1993:
-----------------------------------------

I haven't been able to reproduce this issue using IBM JDK 1.3.1.  It looks as if the ListResourceBundles are being looked up and found correctly.  The JDK first tries to load the class specified in the ResourceBundle.getResourceBundle method and then if that fails it looks for a .properties file with the same name.

I could see you getting the ClassCastException if for some reason you don't have the ListResourceBundle files, but you do have .properties files lying around.  Once upon a time I think we used .properties files instead of the classes.

Or maybe I'm missing something.  Can you describe your environment in more detail?

Thanks.

> proposed fix to ClassCastException in org.apache.xml.res.XMLMessages
> --------------------------------------------------------------------
>
>          Key: XALANJ-1993
>          URL: http://issues.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://issues.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