spring-data-redis icon indicating copy to clipboard operation
spring-data-redis copied to clipboard

NullPointerException with Jedis and sync=true [DATAREDIS-596]

Open spring-projects-issues opened this issue 8 years ago • 0 comments

Renato Duarte Soffiatto opened DATAREDIS-596 and commented

Environment: Spring Boot: 1.4.3 Spring Data Redis: 1.7.7-BUILD-SNAPSHOT (pretty sure it happens with the 1.7.6, but the stack traces were collected from the 1.7.x branch from the github) Jedis: 2.8.2, 2.9.0

Sorry for not having an example project where this error happens.

I am receiving some NullPointerExceptions when using @Cacheable with sync=true with Spring-Data-Redis and Jedis. Unfortunately the error is somewhat intermittent and I was not able to pinpoint what the problem is exactly. What I was able to observe is:

  • It is only happening when a @Cacheable with the sync=true is being processed;
  • It only happens on a cache miss;
  • The NullPointerException happens when the transaction is null on JedisConnection::discard;
  • Another exception trigger the calling of this method: "java.lang.IllegalArgumentException: Incorrect number of transaction results. Expected: 2 Actual: 0". This exception is caught on the inner try of the RedisWriteThroughCallback::doInRedis
  • It does not happen when the connection factory is configured with JedisConnectionFactory::setConvertPipelineAndTxResults(false);
  • It does not matter if the transaction support is being used or not;
  • The methods where this happen have multiple levels of methods annotated with @Cacheable. I'm not sure if this is relevant or not.
  • The NullPointerException is hidden by a failure to translate the exception. Only a ClassCastException is logged: ClassCastException: "java.lang.ClassCastException: org.springframework.data.redis.RedisSystemException cannot be cast to org.springframework.cache.interceptor.CacheOperationInvoker$ThrowableWrapper"

StackTraces of the exceptions:

java.lang.NullPointerException
 	at org.springframework.data.redis.connection.jedis.JedisConnection.discard(JedisConnection.java:740)
 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 	at java.lang.reflect.Method.invoke(Method.java:498)
 	at org.springframework.data.redis.core.CloseSuppressingInvocationHandler.invoke(CloseSuppressingInvocationHandler.java:57)
 	at com.sun.proxy.$Proxy163.discard(Unknown Source)
 	at org.springframework.data.redis.cache.RedisCache$RedisWriteThroughCallback.doInRedis(RedisCache.java:782)
 	at org.springframework.data.redis.cache.RedisCache$RedisWriteThroughCallback.doInRedis(RedisCache.java:742)
 	at org.springframework.data.redis.cache.RedisCache$AbstractRedisCacheCallback.doInRedis(RedisCache.java:469)
 	at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:204)
 	at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:166)
 	at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:154)
 	at org.springframework.data.redis.cache.RedisCache.get(RedisCache.java:119)
 	at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:364)
 	at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:327)
 	at org.springframework.cache.interceptor.CacheInterceptor.invoke(CacheInterceptor.java:61)
 	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
 	at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:656)
 	at br.tur.reservafacil.precificador.application.service.ProdutoService$$EnhancerBySpringCGLIB$$c0b10f66.findByKey(<generated>)
...
java.lang.IllegalArgumentException: Incorrect number of transaction results. Expected: 2 Actual: 0
 	at org.springframework.data.redis.connection.convert.TransactionResultConverter.convert(TransactionResultConverter.java:51)
 	at org.springframework.data.redis.connection.jedis.JedisConnection.exec(JedisConnection.java:762)
 	at sun.reflect.GeneratedMethodAccessor304.invoke(Unknown Source)
 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 	at java.lang.reflect.Method.invoke(Method.java:498)
 	at org.springframework.data.redis.core.CloseSuppressingInvocationHandler.invoke(CloseSuppressingInvocationHandler.java:57)
 	at com.sun.proxy.$Proxy163.exec(Unknown Source)
 	at org.springframework.data.redis.cache.RedisCache$RedisWriteThroughCallback.doInRedis(RedisCache.java:776)
 	at org.springframework.data.redis.cache.RedisCache$RedisWriteThroughCallback.doInRedis(RedisCache.java:742)
 	at org.springframework.data.redis.cache.RedisCache$AbstractRedisCacheCallback.doInRedis(RedisCache.java:469)
 	at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:204)
 	at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:166)
 	at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:154)
 	at org.springframework.data.redis.cache.RedisCache.get(RedisCache.java:119)
 	at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:364)
 	at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:327)
 	at org.springframework.cache.interceptor.CacheInterceptor.invoke(CacheInterceptor.java:61)
 	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
 	at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:656)
 	at br.tur.reservafacil.precificador.application.service.ProdutoService$$EnhancerBySpringCGLIB$$c0b10f66.findByKey(<generated>)
...
java.lang.ClassCastException: org.springframework.data.redis.RedisSystemException cannot be cast to org.springframework.cache.interceptor.CacheOperationInvoker$ThrowableWrapper
 	at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:374)
 	at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:327)
 	at org.springframework.cache.interceptor.CacheInterceptor.invoke(CacheInterceptor.java:61)
 	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
 	at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:656)
 	at br.tur.reservafacil.precificador.application.service.ProdutoService$$EnhancerBySpringCGLIB$$c0b10f66.findByKey(<generated>)
at 
...
org.springframework.data.redis.RedisSystemException: Unknown redis exception; nested exception is java.lang.IllegalArgumentException: Incorrect number of transaction results. Expected: 2 Actual: 0
	at org.springframework.data.redis.FallbackExceptionTranslationStrategy.getFallback(FallbackExceptionTranslationStrategy.java:48)
	at org.springframework.data.redis.FallbackExceptionTranslationStrategy.translate(FallbackExceptionTranslationStrategy.java:38)
	at org.springframework.data.redis.connection.jedis.JedisConnection.convertJedisAccessException(JedisConnection.java:212)
	at org.springframework.data.redis.connection.jedis.JedisConnection.exec(JedisConnection.java:766)
	at sun.reflect.GeneratedMethodAccessor331.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.springframework.data.redis.core.CloseSuppressingInvocationHandler.invoke(CloseSuppressingInvocationHandler.java:57)
	at com.sun.proxy.$Proxy163.exec(Unknown Source)
	at org.springframework.data.redis.cache.RedisCache$RedisWriteThroughCallback.doInRedis(RedisCache.java:777)
	at org.springframework.data.redis.cache.RedisCache$RedisWriteThroughCallback.doInRedis(RedisCache.java:743)
	at org.springframework.data.redis.cache.RedisCache$AbstractRedisCacheCallback.doInRedis(RedisCache.java:470)
	at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:204)
	at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:166)
	at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:154)
	at org.springframework.data.redis.cache.RedisCache.get(RedisCache.java:120)
	at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:364)
	at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:327)
	at org.springframework.cache.interceptor.CacheInterceptor.invoke(CacheInterceptor.java:61)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
	at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:656)
	at br.tur.reservafacil.precificador.application.service.ProdutoService$$EnhancerBySpringCGLIB$$d4646977.findByKey(<generated>)
...

Affects: 1.7.6 (Hopper SR6)

spring-projects-issues avatar Jan 25 '17 18:01 spring-projects-issues