杰克逊在使用Guava的RateLimiter时解析异常

时间:2017-09-07 12:20:54

标签: java android jackson guava

我正在使用Guava的RateLimiter,所以我没有在API上达到每秒最大请求数(I' ts 5 ..)。它工作正常,我从来没有达到速率限制,但我现在有一个奇怪的问题。出于某种原因,它为运行应用程序的5次中的1次提供了6次调用之一的异常:

java.lang.NullPointerException: Attempt to invoke virtual method 'boolean com.fasterxml.jackson.databind.JavaType.equals(java.lang.Object)' on a null object reference
                                               at com.fasterxml.jackson.databind.type.ResolvedRecursiveType.equals(ResolvedRecursiveType.java:103)
                                               at com.fasterxml.jackson.databind.type.TypeBindings$AsKey.equals(TypeBindings.java:458)
                                               at java.util.concurrent.ConcurrentHashMap.putVal(ConcurrentHashMap.java:1014)
                                               at java.util.concurrent.ConcurrentHashMap.putIfAbsent(ConcurrentHashMap.java:1522)
                                               at com.fasterxml.jackson.databind.util.LRUMap.putIfAbsent(LRUMap.java:64)
                                               at com.fasterxml.jackson.databind.type.TypeFactory._fromClass(TypeFactory.java:1274)
                                               at com.fasterxml.jackson.databind.type.TypeFactory._fromParamType(TypeFactory.java:1384)
                                               at com.fasterxml.jackson.databind.type.TypeFactory._fromAny(TypeFactory.java:1154)
                                               at com.fasterxml.jackson.databind.type.TypeFactory._resolveSuperInterfaces(TypeFactory.java:1298)
                                               at com.fasterxml.jackson.databind.type.TypeFactory._fromClass(TypeFactory.java:1247)
                                               at com.fasterxml.jackson.databind.type.TypeFactory._fromAny(TypeFactory.java:1150)
                                               at com.fasterxml.jackson.databind.type.TypeFactory.constructType(TypeFactory.java:618)
                                               at com.fasterxml.jackson.databind.cfg.MapperConfig.constructType(MapperConfig.java:290)
                                               at com.fasterxml.jackson.databind.cfg.MapperConfig.introspectClassAnnotations(MapperConfig.java:320)
                                               at com.fasterxml.jackson.databind.deser.BasicDeserializerFactory.findTypeDeserializer(BasicDeserializerFactory.java:1338)
                                               at com.fasterxml.jackson.databind.DeserializationContext.findRootValueDeserializer(DeserializationContext.java:481)
                                               at com.fasterxml.jackson.databind.ObjectMapper._findRootDeserializer(ObjectMapper.java:3890)
                                               at com.fasterxml.jackson.databind.ObjectMapper._readValue(ObjectMapper.java:3756)
                                               at com.fasterxml.jackson.databind.ObjectMapper.readTree(ObjectMapper.java:2198)
                                               at dk.nykredit.jackson.dataformat.hal.deser.HALBeanDeserializer.deserialize(HALBeanDeserializer.java:27)
                                               at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3789)
                                               at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2913)
                                               at org.springframework.http.converter.json.MappingJackson2HttpMessageConverter.readJavaType(MappingJackson2HttpMessageConverter.java:179)
                                               at org.springframework.http.converter.json.MappingJackson2HttpMessageConverter.read(MappingJackson2HttpMessageConverter.java:174)
                                               at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:89)
                                               at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:738)
                                               at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:723)
                                               at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:544)
                                               at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:506)
                                               at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:455)
                                               at nl.app.App.API.RestClient_.getAdviseurs(RestClient_.java:117)
                                               at nl.app.App.Services.AdviseurService.getAdviseur(AdviseurService.java:60)
                                               at nl.app.App.Services.AdviseurService.getAdviseurAsync(AdviseurService.java:49)
                                               at nl.app.App.Services.AdviseurService_.access$101(AdviseurService_.java:19)
                                               at nl.app.App.Services.AdviseurService_$2.execute(AdviseurService_.java:66)
                                               at org.androidannotations.api.BackgroundExecutor$Task.run(BackgroundExecutor.java:405)
                                               at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:428)
                                               at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                                               at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:272)
                                               at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)

1 个答案:

答案 0 :(得分:0)

该例外似乎与RateLimiter没有任何关系。堆栈跟踪说Spring和/或Jackson试图通过对.equals()引用的反射来调用null。我的猜测是你将null传递给你不应该的东西 - 如果速率限制器没有足够的许可证,你可能会返回null吗?

如果没有看到有问题的代码,很难确切地说出导致此错误的原因。尝试制作一个复制错误的MCVE - 可能只是创建MCVE就足以让您找到问题。