Protect against cache overwrites.

git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@383546 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Hiram R. Chirino 2006-03-06 14:25:36 +00:00
parent c3e10f5438
commit db9144a985
1 changed files with 16 additions and 4 deletions

View File

@ -400,13 +400,25 @@ final public class OpenWireFormat implements WireFormat {
nextMarshallCacheIndex=0;
}
marshallCache[i] = o;
Short index = new Short(i);
marshallCacheMap.put(o, index);
return index;
// We can only cache that item if there is space left.
if( marshallCacheMap.size() < MARSHAL_CACHE_SIZE ) {
marshallCache[i] = o;
Short index = new Short(i);
marshallCacheMap.put(o, index);
return index;
} else {
// Use -1 to indicate that the value was not cached due to cache being full.
return new Short((short)-1);
}
}
public void setInUnmarshallCache(short index, DataStructure o) {
// There was no space left in the cache, so we can't
// put this in the cache.
if( index == -1 )
return;
unmarshallCache[index]=o;
}