3 Replies Latest reply on Dec 13, 2012 8:35 PM by sannsims

    NullPointerException: Null values are not supported! thrown when using Spring @Cacheable

    sannsims Newbie

      Hello everyone!  I'm working on a Infinispan Cache (5.1.6) demo which we want to consider implementing in a project.  I'm annotating my methods using Spring 3.1.RC1 annotation:  @Cacheable and @CacheEvict.  Thus far, all I done is declaratively configured cache.  There haven't been any errors when I invoke a method to get all data from the database.  However, when I tried to insert data, I get the following error:

       

           java.lang.NullPointerException: Null values are not supported!

       

      Below is the output from the logs of the object I'm trying to persist to the database which none of the values are null.

      2012-12-08 22:17:43,226 INFO  [STDOUT] (http-127.0.0.1-8280-1) Executing PetDAO insertPet() ID: 12 Name: Lassie Origin: The Lassie Show Type: Dog

       

      Here's the code from the data broker:

       

       @Cacheable( value = "pets" )
       public List<Pet> getAllPets()  //works fine
       {
        System.out.println( "Executing PetDAO getAllPets()" );
        List<Pet> allPets = jdbcTemplate.query( "select * from pets order by id", new PetMapper() );
        return allPets;
       }
      
       @Cacheable( value = "pets" )
       public void insertPet( Pet pet )  //problem when invoking this method
       {
        System.out.println( "Executing PetDAO insertPet() " + pet.toString() );
        jdbcTemplate.update( "insert into pets ( name, origin, id, type ) " +
          "values ( ?, ?, ?, ? )", pet.getName(), pet.getOrigin(), pet.getId(), pet.getType() );
       }
      

      Note: insertPet will only work without the @Cacheable annotation???

       

       <namedCache name="pets">
        <eviction 
         maxEntries="10"
         strategy="LRU"
        />
        <expiration
         wakeUpInterval="500"
         lifespan="60000"
         maxIdle="1000"
        />
       </namedCache>
      

      Below is the error from the Rest Server.  Internet search on this error came up empty. If anyone has a suggestion/solution on how to resolve this error or even how to troubleshoot it, I would appreciate it!  I'm stumped?!

       

      2012-12-08 22:17:43,413 ERROR [STDERR] (http-127.0.0.1-8280-1) java.lang.NullPointerException: Null values are not supported!
      2012-12-08 22:17:43,413 ERROR [STDERR] (http-127.0.0.1-8280-1)  at org.infinispan.CacheImpl.assertKeyValueNotNull(CacheImpl.java:203)
      2012-12-08 22:17:43,413 ERROR [STDERR] (http-127.0.0.1-8280-1)  at org.infinispan.CacheImpl.put(CacheImpl.java:699)
      2012-12-08 22:17:43,413 ERROR [STDERR] (http-127.0.0.1-8280-1)  at org.infinispan.CacheImpl.put(CacheImpl.java:694)
      2012-12-08 22:17:43,413 ERROR [STDERR] (http-127.0.0.1-8280-1)  at org.infinispan.CacheSupport.put(CacheSupport.java:53)
      2012-12-08 22:17:43,413 ERROR [STDERR] (http-127.0.0.1-8280-1)  at org.infinispan.spring.provider.SpringCache.put(SpringCache.java:83)
      2012-12-08 22:17:43,413 ERROR [STDERR] (http-127.0.0.1-8280-1)  at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:232)
      2012-12-08 22:17:43,413 ERROR [STDERR] (http-127.0.0.1-8280-1)  at org.springframework.cache.interceptor.CacheInterceptor.invoke(CacheInterceptor.java:66)
      2012-12-08 22:17:43,429 ERROR [STDERR] (http-127.0.0.1-8280-1)  at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
      2012-12-08 22:17:43,429 ERROR [STDERR] (http-127.0.0.1-8280-1)  at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:622)
      2012-12-08 22:17:43,429 ERROR [STDERR] (http-127.0.0.1-8280-1)  at com.infinispan.rest.dao.PetDAO$$EnhancerByCGLIB$$de9d088a_2.insertPet(<generated>)
      2012-12-08 22:17:43,429 ERROR [STDERR] (http-127.0.0.1-8280-1)  at com.infinispan.rest.services.PetBroker.addPet(PetBroker.java:34)
      2012-12-08 22:17:43,429 ERROR [STDERR] (http-127.0.0.1-8280-1)  at com.infinispan.rest.services.PetService.addPet(PetService.java:40)
      2012-12-08 22:17:43,429 ERROR [STDERR] (http-127.0.0.1-8280-1)  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      2012-12-08 22:17:43,429 ERROR [STDERR] (http-127.0.0.1-8280-1)  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      2012-12-08 22:17:43,429 ERROR [STDERR] (http-127.0.0.1-8280-1)  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      2012-12-08 22:17:43,429 ERROR [STDERR] (http-127.0.0.1-8280-1)  at java.lang.reflect.Method.invoke(Method.java:597)
      2012-12-08 22:17:43,429 ERROR [STDERR] (http-127.0.0.1-8280-1)  at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:155)
      2012-12-08 22:17:43,429 ERROR [STDERR] (http-127.0.0.1-8280-1)  at org.jboss.resteasy.core.ResourceMethod.invokeOnTarget(ResourceMethod.java:257)
      2012-12-08 22:17:43,429 ERROR [STDERR] (http-127.0.0.1-8280-1)  at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:222)
      2012-12-08 22:17:43,429 ERROR [STDERR] (http-127.0.0.1-8280-1)  at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:211)
      2012-12-08 22:17:43,429 ERROR [STDERR] (http-127.0.0.1-8280-1)  at org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:525)
      2012-12-08 22:17:43,429 ERROR [STDERR] (http-127.0.0.1-8280-1)  at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:502)
      2012-12-08 22:17:43,429 ERROR [STDERR] (http-127.0.0.1-8280-1)  at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:119)
      2012-12-08 22:17:43,429 ERROR [STDERR] (http-127.0.0.1-8280-1)  at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:208)
      2012-12-08 22:17:43,429 ERROR [STDERR] (http-127.0.0.1-8280-1)  at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:55)
      2012-12-08 22:17:43,429 ERROR [STDERR] (http-127.0.0.1-8280-1)  at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:50)
      2012-12-08 22:17:43,429 ERROR [STDERR] (http-127.0.0.1-8280-1)  at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      2012-12-08 22:17:43,429 ERROR [STDERR] (http-127.0.0.1-8280-1)  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
      2012-12-08 22:17:43,429 ERROR [STDERR] (http-127.0.0.1-8280-1)  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      2012-12-08 22:17:43,429 ERROR [STDERR] (http-127.0.0.1-8280-1)  at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
      2012-12-08 22:17:43,429 ERROR [STDERR] (http-127.0.0.1-8280-1)  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
      2012-12-08 22:17:43,429 ERROR [STDERR] (http-127.0.0.1-8280-1)  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      2012-12-08 22:17:43,429 ERROR [STDERR] (http-127.0.0.1-8280-1)  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
      2012-12-08 22:17:43,429 ERROR [STDERR] (http-127.0.0.1-8280-1)  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
      2012-12-08 22:17:43,429 ERROR [STDERR] (http-127.0.0.1-8280-1)  at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
      2012-12-08 22:17:43,429 ERROR [STDERR] (http-127.0.0.1-8280-1)  at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
      2012-12-08 22:17:43,429 ERROR [STDERR] (http-127.0.0.1-8280-1)  at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
      2012-12-08 22:17:43,429 ERROR [STDERR] (http-127.0.0.1-8280-1)  at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
      2012-12-08 22:17:43,429 ERROR [STDERR] (http-127.0.0.1-8280-1)  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
      2012-12-08 22:17:43,429 ERROR [STDERR] (http-127.0.0.1-8280-1)  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      2012-12-08 22:17:43,429 ERROR [STDERR] (http-127.0.0.1-8280-1)  at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
      2012-12-08 22:17:43,429 ERROR [STDERR] (http-127.0.0.1-8280-1)  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      2012-12-08 22:17:43,429 ERROR [STDERR] (http-127.0.0.1-8280-1)  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
      2012-12-08 22:17:43,429 ERROR [STDERR] (http-127.0.0.1-8280-1)  at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
      2012-12-08 22:17:43,429 ERROR [STDERR] (http-127.0.0.1-8280-1)  at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
      2012-12-08 22:17:43,429 ERROR [STDERR] (http-127.0.0.1-8280-1)  at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
      2012-12-08 22:17:43,429 ERROR [STDERR] (http-127.0.0.1-8280-1)  at java.lang.Thread.run(Thread.java:662)

       

      Thanks for reading my post!

        • 1. Re: NullPointerException: Null values are not supported! thrown when using Spring @Cacheable
          Vladimir Blagojevic Master

          Well, it seems like values you are pushing into cache are null? Investigate why is that so!

          • 2. Re: NullPointerException: Null values are not supported! thrown when using Spring @Cacheable
            sannsims Newbie

            The object does contain values.  Here is the print statement from just inside the "insertPet" method:

             

            2012-12-08 22:17:43,226 INFO  [STDOUT] (http-127.0.0.1-8280-1) Executing PetDAO insertPet() ID: 12 Name: Lassie Origin: The Lassie Show Type: Dog

             

            • 3. Re: NullPointerException: Null values are not supported! thrown when using Spring @Cacheable
              sannsims Newbie

              I stepped through Spring's code to determine if my object parameters were being passed as null and it's not.  I'm seeing the values I submitted within Spring's objects.  While stepping through the code, it seems the problem is within "inspectCacheables" method of the CacheAspectSupport object.  The CacheAspectSupport args property does contain the values I passed:  [ID: 31 Name: Eddie Origin: Frazier Type: dog].  The following code was copied from the CacheAspectSupport class:

               

              1.     if (!updateRequire) {
              2.      for (Cache cache : context.getCaches()) {
              3.       Cache.ValueWrapper wrapper = cache.get(key);
              4.       if (wrapper != null) {
              5.        retVal = wrapper.get();
              6.        localCacheHit = true;
              7.        break;
              8.       }
                    }
                   }

               

              The problem occurs with the "cache.get(key)" line 3, it returns a null wrapper.  The cache object is an instance of the org.infinispan.spring.provider.SpringCache which implements the Cache interface.  When I click on the cache object in the debugger, it shows the following:  Cache 'pets' @Node-A-39634.

               

              I first notice this error while using Spring JARs 3.1.0.RC1.  So, I downloaded the latest code from Spring 3.2.0.RC2 and the latest infinispan-spring.jar from the Infinispan Beta release. Unfortunately, I still get the same results:  "java.lang.NullPointerException: Null values are not supported!"  I also updated my DAO code as follows:

               

              //THIS DOES NOT WORK AT ALL
              @Cacheable( value = "pets", key = "#pet.id" ) //does not work
              @Cacheable( value = "pets" )  //does not work
              @Cacheable( value = "test" )  //does not work
              public void insertPet( Pet pet )
              {
                System.out.println( "Executing PetDAO insertPet() " + pet.toString() );
                jdbcTemplate.update( "insert into pets ( name, origin, id, type ) " +
                  "values ( ?, ?, ?, ? )", pet.getName(), pet.getOrigin(), pet.getId(), pet.getType() );
              }

              //THIS WORKS FINE, NO PROBLEMS
              @Cacheable( value = "pets" )
              public List<Pet> getAllPets()
              {
                System.out.println( "Executing PetDAO getAllPets()" );
                List<Pet> allPets = jdbcTemplate.query( "select * from pets order by id", new PetMapper() );
                return allPets;
              }


              I would have liked to debug this code further, however time does not permit right now.  Has anyone had this issue before?  Can anyone get this to work???

              Thanks!