Cached collections don't handle null values correctly
-----------------------------------------------------
Key: JBCACHE-398
URL:
https://issues.jboss.org/browse/JBCACHE-398
Project: JBoss Cache
Issue Type: Bug
Security Level: Public(Everyone can see)
Components: Legacy POJO Cache
Affects Versions: 1.2.4SP1
Reporter: twundke
Assignee: Scott Marlow
Fix For: 1.3.0.GA
When a null value is placed into a cached collection (CachedListImpl etc), the node for
that element is removed from the cache. This is because TreeCacheAopDelegate._putObject()
calls _removeObject() when provided with a null value.
This behaviour breaks size() in the case where a collection allows null values to be
stored (ArrayList, HashMap etc). The cache needs to explicitly store a null object (eg.
org.jboss.util.Null) so that collections work as expected.
I have a fix, which basically involves calling the following methods in the correct
places:
private Object toNullObject( Object aObject )
{
if ( aObject == null )
{
return Null.VALUE;
} // if
else
{
return aObject;
} // else
} // toNullObject
private Object toNullValue( Object aObject )
{
if ( Null.VALUE.equals( aObject ) )
{
return null;
} // if
else
{
return aObject;
} // else
} // toNullObject
So, for example, we can use:
public Object get() {
...
return toNullValue(cache_.getObject(...));
}
These methods should be placed in a common area to be called by each collection class. In
addition to this, the CachedListImpl.checkArgument(Object) method should be removed.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: