3 Replies Latest reply on Sep 14, 2017 12:42 PM by Galder Zamarreño

    How to create DecoratedCache in Infinispan 9.1?

    Michal Stehlik Newbie

      Hi All,

       

      We are upgrading our system from Infinispan 8.2.8 to Infinispan 9.1 and I found problem with creating DecoratedCache. Previous usage was following:

      final DecoratedCache<K, V> decoratedCacheGet = new DecoratedCache<>(cache.getAdvancedCache(), Flag.FORCE_WRITE_LOCK);
      

      this kind of implementation works fine for 8.2.8 but when I run same code, I get ClassCastException:

       

      java.lang.ClassCastException: org.infinispan.cache.impl.EncoderCache cannot be cast to org.infinispan.cache.impl.CacheImpl
      at org.infinispan.cache.impl.DecoratedCache.<init>(DecoratedCache.java:69)
      at org.infinispan.cache.impl.DecoratedCache.<init>(DecoratedCache.java:55)
      

       

      I take a look into code and line which cause currently this problem is:

      cacheImplementation = (CacheImpl<K, V>) delegate;
      

      It seems, that in version 9.1: cache.getAdvancedCache returns EncoderCache, this is fine, problem is, there is no relation between EncoderCache and CacheImpl in class hierarchy, therefore, this casting cause exception.

       

       

      According to documentation, creating DecoratedCache in our source code is syntactically correct. Is there some different way how to create DecoratedCache?