TreeCacheAop Map field support and java.util.ConcurrentModi
gabrieli Jun 13, 2004 1:16 PMHello,
I'm a new user of TreeCacheAop (v1.01). My cached (POJO) class is constructed of a private HashMap member and a private reference to itself (same class) [to build a tree-like object hierarchy/graph].
While loading (putObject) my objects' hierarchy to the TreeCacheAop I'm getting the following exception:
Exception in thread "main" java.util.ConcurrentModificationException
at java.util.HashMap$HashIterator.nextEntry(HashMap.java(Compiled Code))
at java.util.HashMap$KeyIterator.next(HashMap.java:894)
at org.jboss.cache.aop.TreeCacheAop._removeObject(TreeCacheAop.java:548)
at org.jboss.cache.aop.TreeCacheAop._removeObject(TreeCacheAop.java:533)
at org.jboss.cache.aop.TreeCacheAop.removeObject(TreeCacheAop.java:503)
at org.jboss.cache.aop.TreeCacheAop.handleObjectGraph(TreeCacheAop.java:366)
at org.jboss.cache.aop.TreeCacheAop._putObject(TreeCacheAop.java:209)
at org.jboss.cache.aop.TreeCacheAop.putObject(TreeCacheAop.java:133)
at org.jboss.cache.aop.TreeCacheAop.putObject(TreeCacheAop.java:114)
at org.amir.TestDeviceCache.test(TestDeviceCache.java:245)
at org.amir.TestDeviceCache.main(TestDeviceCache.java:327)
It seems that the source of the exception is internal to the TreeCacheAop. I've located the 'iterator” that caused the exception:
~TreeCacheAop.java:548 method: "_removeObject":
protected Object _removeObject(Fqn fqn, boolean removeCacheInterceptor) throws Exception
{
Â…
} else if (Map.class.isAssignableFrom(clazz)) {
Map values = get(fqn).getChildren();
if (values != null) {
for (Iterator i = values.keySet().iterator(); i.hasNext();) {
Object key = i.next(); // EXCEPTION HERE (line 548)
_removeObject(new Fqn(fqn, key), removeCacheInterceptor);
}
}
} else if (Collection.class.isAssignableFrom(clazz)) {
Map values = get(fqn).getChildren();
int size = values == null ? 0 : values.size();
for (int i = 0; i < size; i++) {
_removeObject(new Fqn(fqn, new Integer(i)), removeCacheInterceptor);
}
}
Am I using the TreeCacheAop (Map support) wrong or is it something else?
My POJO class is:
public class Device {
public String name=null;
public Device parent=null;
public Map attributes=null;
public Device(){}
public String getName() {
return name;
}
public Device getParent() {
return parent;
}
public void setName(String name) {
this.name = name;
}
public void setParent(Device device) {
parent = device;
}
public void setAttributes(Map attrbiutesMap)
{
this.attributes = attrbiutesMap;
}
public Object getProperty(String propName)
{
Object obj = attributes.get(propName);
if (obj==null && parent != null){
obj = parent.getProperty(propName);
}
return obj;
}
}
The class is complied with aopc complier and is working great until its HashMap is filled and the object is begin referenced by another.