4 Replies Latest reply on Dec 11, 2006 8:04 PM by ben.wang

    PojoCache 2.0: Bug in CacheApiUtil.exists?

    chasta

      Hi,
      Please note the following code snippet from CacheApiUtil.java:

       public static boolean exists(CacheSPI cache, Fqn fqn, Object key)
       {
       if(cache.getCacheLoader() != null)
       {
       // Has cache loader
       return (cache.get(fqn, key) != null) ? true : false;
       }
      
       Node node = cache.getRoot().getChild(fqn);
       if(node == null) return false;
       Map map = node.getData();
       return (map.values().contains(key)) ? true: false; // <-- HERE
       }
      

      (From latest CVS version of JBossCache 2.0)

      Why is the contains() called on the map values and not on the map keys? If I understand the intention correctly, isn't this a bug?

      This affects the following snippet:

      From CacheFieldInterceptor.java:
       private boolean isPojoDetached(Invocation invocation)
       {
       boolean detached = false;
      
       // PojoInstance.KEY is "PojoInstance"
       // This will always be false, since we're giving it the key and it looks for
       // the value
       if(!CacheApiUtil.exists(cache_, fqn_, PojoInstance.KEY)) // <-- HERE
       {
       detached = true;
       Object obj = invocation.getTargetObject();
       ...
      


      It affects our usage of the cache - the cache throws us spurious exceptions about objects being detached from it (PojoCacheAlreadyDetachedException. We're using local mode with optimistic locking).

      Is this a bug? Or perhaps I'm missing something? And if so, any idea why are we getting these spurious exceptions?