[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-2142) PersistentMap.put(), remove() may return UNKNOWN object that can cause ClassCastException in client code

Jeff Schnitzer (JIRA) noreply at atlassian.com
Mon Oct 30 19:07:05 EST 2006


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-2142?page=comments#action_25034 ] 

Jeff Schnitzer commented on HHH-2142:
-------------------------------------

This is definitely happening.  I'm getting ClassCastException to MarkerObject from this line:

EnabledFilter filt = list.getEnabledFilters().remove(className);

Doing the get() and remove() as separate steps works fine.  This is with JBoss 4.0.5.GA.

> PersistentMap.put(), remove() may return UNKNOWN object that can cause ClassCastException in client code
> --------------------------------------------------------------------------------------------------------
>
>          Key: HHH-2142
>          URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2142
>      Project: Hibernate3
>         Type: Bug

>   Components: core
>     Versions: 3.2.0.cr5
>     Reporter: Andrzej Miazga

>
>
> Here is some code in Hibernate 3.2.0cr5 that may cause this behaviour. I'm not sure if this is a bug but it surely affects the client code.
> AbstractPersistentCollection:
> protected Object readElementByIndex(Object index) {
>   if (!initialized) {
>     ...
>     return persister.getElementByIndex( entry.getLoadedKey(), index, session, owner );
>   }
>   ...
>   return UNKNOWN;
> }	
> PersistentMap (extends AbstractPersistentCollection):
>   public Object put(Object key, Object value) {
> 		if ( isPutQueueEnabled() ) {
> 			Object old = readElementByIndex( key );
> 			queueOperation( new Put( key, value, old ) );
> 			return old;
> 		}
> 		...
> So, there is a possibility to return UNKNOWN instance (MarkerObject) to the client code as the result of Map.put().
> In version 3.1.3 this worked fine, but the implementation was different:
> 	public Object put(Object key, Object value) {
> 		Object old = isPutQueueEnabled() ?
> 				readElementByIndex(key) : UNKNOWN;
> 		if ( old==UNKNOWN ) {
> 			write();
> 			return map.put(key, value);
> 		}
> ...
> 	} 

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira




More information about the hibernate-issues mailing list