LRUCachePolicy incompatiblity WAS Re: [jboss-dev] Remoting shutdown errors and warnings

Adrian Brock abrock at redhat.com
Thu Sep 4 11:17:28 EDT 2008


On Thu, 2008-09-04 at 16:48 +0200, Adrian Brock wrote:
> public java.util.Set getContents();
>   Code:
>    0:   aload_0
>    1:   getfield        #12; //Field m_map:Ljava/util/HashMap;
>    4:   invokevirtual   #13; //Method
> java/util/HashMap.keySet:()Ljava/util/Set;
>    7:   areturn
> 

I also don't think this method is very clever.

   public Set getContents()
   {
      return m_map.keySet();
   }

Since the m_map is an unsynchronized HashMap by default
this code can suffer from a number of problems:

1) It is not synchronized so you could cause
the LRUPool to hit a ConcurrentModificationException
when iterating over the map if you do Set.remove().

>From the javadoc:
"The set supports element removal, which removes the
 corresponding mapping from this map"

2) Iterating over the set itself could have the
reverse CME problem for the caller if the pool modifies
the HashMap.

3) Sun's implementation of HashMap is known to
go into an infinite loop using 100% cpu 
due to internal datastructure corruption when
you don't synchronize access properly.

-- 
xxxxxxxxxxxxxxxxxxxxxxxxxxxx
Adrian Brock
Chief Scientist
JBoss, a division of Red Hat
xxxxxxxxxxxxxxxxxxxxxxxxxxxx




More information about the jboss-development mailing list