Uploaded image for project: 'Infinispan'
  1. Infinispan
  2. ISPN-15076

CacheStream NPE in a tx with entryReduction

XMLWordPrintable

      Given following cache configuration in Wildfly 26:

      public class CacheConfiguration
      {
          public static final String DEFAULT_CACHE_NAME = "DefaultCacheName";
          @Produces
          @ApplicationScoped
          public EmbeddedCacheManager defaultCacheManager()
          {
              final GlobalConfigurationBuilder globalConfigurationBuilder =
                  new GlobalConfigurationBuilder().nonClusteredDefault()
                      .jmx()
                      .defaultCacheName( DEFAULT_CACHE_NAME );
      
              ConfigurationBuilderHolder configurationBuilderHolder =
                  new ConfigurationBuilderHolder( Thread.currentThread()
                      .getContextClassLoader(), globalConfigurationBuilder );
      
              createCacheConfig( configurationBuilderHolder );
      
              configurationBuilderHolder.validate();
              return new DefaultCacheManager( configurationBuilderHolder, true );
          }
      
          private void createCacheConfig( final ConfigurationBuilderHolder aConfigurationBuilderHolder )
          {
              aConfigurationBuilderHolder.newConfigurationBuilder( DEFAULT_CACHE_NAME )
                  .transaction()
                  .transactionMode( TransactionMode.TRANSACTIONAL )
                  .lockingMode( LockingMode.OPTIMISTIC )
                  .memory()
                  .whenFull( EvictionStrategy.NONE )
                  .locking()
                  .isolationLevel( IsolationLevel.READ_COMMITTED );
          }
      } 

      When performing filtering:

      @ApplicationScoped
      public class TestBean{
          @Inject
          private EmbeddedCacheManager cacheManager;
      
          public void testMethod(){
              String name = "SomeName";
              addConfiguration( name );
              cacheManager.getCache( name ).values()
                  .stream()
                  //some filtering
                  .filter( obj -> obj.toString().length()>10)
                  // throws NPE
                  .findFirst();
          }
      
          private void addConfiguration( final String aCacheName )
          {
              if( cacheManager.getCacheConfiguration( aCacheName ) == null )
              {
                  cacheManager.defineConfiguration( aCacheName, cacheManager.getDefaultCacheConfiguration() );
              }
          }
      }

      When above (similar) code is executed we're getting following exceptions:

       Caused by: java.util.concurrent.CompletionException: java.lang.NullPointerException: item1 is null
           at org.infinispan:ispn-14.0//org.infinispan.util.concurrent.CompletionStages.join(CompletionStages.java:87)
           at org.infinispan:ispn-14.0//org.infinispan.stream.impl.AbstractCacheStream.performPublisherOperation(AbstractCacheStream.java:200)
           at org.infinispan:ispn-14.0//org.infinispan.stream.impl.DistributedCacheStream.findAny(DistributedCacheStream.java:327)
           at org.infinispan:ispn-14.0//org.infinispan.stream.impl.DistributedCacheStream.findFirst(DistributedCacheStream.java:321)
           at org.infinispan:ispn-14.0//org.infinispan.util.AbstractDelegatingCacheStream.findFirst(AbstractDelegatingCacheStream.java:315)
           at deployment.XXX.war//com.xxx.yyy.xxx.TestBean.testMethod
           ... 49 more
       Caused by: java.lang.NullPointerException: item1 is null
           at java.base/java.util.Objects.requireNonNull(Objects.java:235)
           at org.infinispan:ispn-14.0//io.reactivex.rxjava3.core.Flowable.just(Flowable.java:3067)
           at java.base/java.util.concurrent.CompletableFuture.biApply(CompletableFuture.java:1311)
           at java.base/java.util.concurrent.CompletableFuture.biApplyStage(CompletableFuture.java:1329)
           at java.base/java.util.concurrent.CompletableFuture.thenCombine(CompletableFuture.java:2210)
           at java.base/java.util.concurrent.CompletableFuture.thenCombine(CompletableFuture.java:144)
           at org.infinispan:ispn-14.0//org.infinispan.reactive.publisher.impl.LocalClusterPublisherManagerImpl.entryReduction(LocalClusterPublisherManagerImpl.java:124)
           at org.infinispan:ispn-14.0//org.infinispan.stream.impl.AbstractCacheStream.performPublisherOperation(AbstractCacheStream.java:197) 

      The same code works fine with Infinispan 13, I suspect that ISPN-13504 (Implement cache sets using publishers) is the change that caused this exception. 

              wburns@redhat.com Will Burns
              pgadecki Pawel Gadecki (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: