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

Andrzej Miazga (JIRA) noreply at atlassian.com
Thu Oct 12 05:40:24 EDT 2006


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