[infinispan-dev] Making confusion between different remove() APIs

Sanne Grinovero sanne.grinovero at gmail.com
Sat Oct 31 12:37:12 EDT 2009


Hello,
I was writing this code:

   boolean cleared = cache.remove(key);

and then I'd thought "let's add a Flag", resulting in:

   boolean cleared = cache.remove(key, Flag.SKIP_CACHE_STORE);

Considering that CacheDelegate contains the following 3 overloaded
"remove" methods:

         ====== CacheDelegate<K,V> ======

public final boolean remove(Object key, Object value) {
      return remove(key, value, (Flag[]) null);
}

public final boolean remove(Object key, Object oldValue, Flag... flags) {
...
}

public final V remove(Object key, Flag... flags) {
...
}
         ====== end code snippet ======

Guess which one is called?
The first one, interpreting my Flag as a value, and obviously my code
was broken.

It's fixed by using:

cache.remove(keyOfLock, new Flag[]{Flag.SKIP_CACHE_STORE});

IMHO it's quite bad already that the CHM has different remove
variants, one returning the previous object and one returning a
boolean "removed or not removed", but this API in Infinispan is making
it even harder.
It would be safer to mandate the array form for Flags, even if I don't
like that; do you have a better idea?

Regards,
Sanne



More information about the infinispan-dev mailing list