8 Replies Latest reply on Jan 26, 2011 7:07 PM by Miroslav Pokorny

    Cache.keySet() | values() | entrySet() .iterator().remove() throws UOE...

    Miroslav Pokorny Newbie

      It would be advantageous if remove was supported as there no practical reason for not allowing this operation. I wrote a quick wrapper that tracks the last key given and does a cache.remove( lastKeyOut ) to verify what i already knew the cache *is* concurrent so removing is not a big deal.

       

      I have included 3 tests w/ the thrown exception below each.

       

          public void testKeySetIterator() {

              final EmbeddedCacheManager manager = new DefaultCacheManager();

              final org.infinispan.Cache<String, String> cache = manager.getCache();

       

              final String key1 = "key1";

              final String key2 = "key2";

              final String key3 = "key3";

              final String value1 = "value1";

              final String value2 = "value2";

              final String value3 = "value3";

       

              cache.put(key1, value1);

              cache.put(key2, value2);

              cache.put(key3, value3);

       

              for (final Iterator<String> keys = cache.keySet().iterator(); keys.hasNext();) {

                  keys.next();

                  keys.remove();

              }

       

              cache.stop();

          }

       

      java.lang.UnsupportedOperationException

          at org.infinispan.util.Immutables$ImmutableIteratorWrapper.remove(Immutables.java:283)

          at cache.infinispan.InfinispanCacheTest.testKeySetIterator(InfinispanCacheTest.java:89)

          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

       

          public void testValuesIterator() {

              final EmbeddedCacheManager manager = new DefaultCacheManager();

              final org.infinispan.Cache<String, String> cache = manager.getCache();

       

              final String key1 = "key1";

              final String key2 = "key2";

              final String key3 = "key3";

              final String value1 = "value1";

              final String value2 = "value2";

              final String value3 = "value3";

       

              cache.put(key1, value1);

              cache.put(key2, value2);

              cache.put(key3, value3);

       

              for (final Iterator<String> values = cache.values().iterator(); values.hasNext();) {

                  values.next();

                  values.remove();

              }

       

              cache.stop();

          }

       

      java.lang.UnsupportedOperationException

          at org.infinispan.util.Immutables$ImmutableIteratorWrapper.remove(Immutables.java:283)

          at cache.infinispan.InfinispanCacheTest.testValuesIterator(InfinispanCacheTest.java:112)

       

       

          public void testEntrySetIterator() {

              final EmbeddedCacheManager manager = new DefaultCacheManager();

              final org.infinispan.Cache<String, String> cache = manager.getCache();

       

              final String key1 = "key1";

              final String key2 = "key2";

              final String key3 = "key3";

              final String value1 = "value1";

              final String value2 = "value2";

              final String value3 = "value3";

       

              cache.put(key1, value1);

              cache.put(key2, value2);

              cache.put(key3, value3);

       

              for (final Iterator<Entry<String, String>> entries= cache.entrySet().iterator(); entries.hasNext();) {

                  entries.next();

                  entries.remove();

              }

       

              cache.stop();

          }

       

      java.lang.UnsupportedOperationException

          at org.infinispan.util.Immutables$ImmutableIteratorWrapper.remove(Immutables.java:283)

          at cache.infinispan.InfinispanCacheTest.testEntrySetIterator(InfinispanCacheTest.java:135)