1 Reply Latest reply on Jul 25, 2005 8:42 PM by ben.wang

    Calling .get() on cached Map causes key to be added to Map

    umk

      Hi,

      Could someone please explain this unexpected behavior using standalone JBoss Cache v1.2.3:
      - I add a Map object to a TreeCacheAOP instance
      - Retrieve the Map from the cache and call get method on map
      - Just calling get causes the key queried for to be added to the Map. This does not follow the contract of standard Java Maps.

      Output of the System.out lines in the below sample:
      ...
      false
      true

      import java.util.HashMap;
      import java.util.Map;
      
      import org.jboss.cache.PropertyConfigurator;
      import org.jboss.cache.aop.TreeCacheAop;
      
      public class CacheMapTest {
      
       private static final String DB_TEST_MAP = "/db/testMap";
      
       private static final String MY_KEY = "myKey";
      
       public static void main(String[] args) throws Exception {
       TreeCacheAop cache = new TreeCacheAop();
       PropertyConfigurator config = new PropertyConfigurator();
       config.configure(cache, "META-INF/replSync-service.xml");
       cache.startService();
      
       cache.putObject(DB_TEST_MAP, new HashMap());
      
       Map testMap = (Map) cache.getObject(DB_TEST_MAP);
       System.out.println(testMap.containsKey(MY_KEY));
       testMap.get(MY_KEY);
       System.out.println(testMap.containsKey(MY_KEY));
       }
      
      }
      


      Thanks!