问题
I am facing a strange NPE when starting Apache Curator's ServiceProvider
. This happens intermittently on the servers, but I was not able to reproduce the error locally, that's why it's so difficult to know what's the problem.
Here's the code:
CuratorFramework curatorFramework = CuratorFrameworkFactory.newClient(zookeeperConnectString, new RetryNTimes(5, 1000));
curatorFramework.start();
ServiceDiscovery<Void> serviceDiscovery = ServiceDiscoveryBuilder.builder(Void.class).basePath(ZK_BASE_PATH).client(curatorFramework).build();
serviceDiscovery.start();
ServiceProvider<Void> serviceProvider = serviceDiscovery.serviceProviderBuilder().serviceName(ZK_SERVICE_NAME).build();
serviceProvider.start();
Here's the stack trace:
Caused by: java.lang.NullPointerException
at org.codehaus.jackson.JsonFactory.createJsonParser(JsonFactory.java:604)
at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1973)
at org.apache.curator.x.discovery.details.JsonInstanceSerializer.deserialize(JsonInstanceSerializer.java:50)
at org.apache.curator.x.discovery.details.ServiceCacheImpl.addInstance(ServiceCacheImpl.java:193)
at org.apache.curator.x.discovery.details.ServiceCacheImpl.start(ServiceCacheImpl.java:96)
at org.apache.curator.x.discovery.details.ServiceProviderImpl.start(ServiceProviderImpl.java:67)
What is happening is that in ServiceCacheImpl#addInstance
a call to childData.getData()
is returning null, and passing it to be deserialized, what obviously causes the NPE.
I'm using Apache Curator version 2.11.0.
Has anyone else faced the same issue? Thanks!
来源:https://stackoverflow.com/questions/42007102/apache-curator-npe-in-jsoninstanceserializer