Kislay Verma commented on CURATOR-453:

I was using a custom class (POJO with 4 String fields and JsonRootName 
annotation) with Curator's JsonInstanceSerializer serializer.

While registering the service, this object wasn't getting posted to Zookeeper 
(though the node got created with new id). Then doing ServiceProvider.start() 
in a different place (code given above) is when this NPE comes. 

I stopped using the POJO and started to post only basic data 
(ServiceProvider<Void>), and then both problems went away. The data would get 
loaded in Zookeeper, and this piece does not throw NPE.

Not sure why this exception would come at ServiceProvider.start() instead of 
coming at getInstance()? Also. perhaps the error reporting can be better than 
an NPE which is difficult to debug.

> NPE in ServiceCacheImpl.start() because child.getData() returns null
> --------------------------------------------------------------------
>                 Key: CURATOR-453
>                 URL: https://issues.apache.org/jira/browse/CURATOR-453
>             Project: Apache Curator
>          Issue Type: Bug
>          Components: General
>    Affects Versions: 4.0.0
>            Reporter: Kislay Verma
>            Priority: Major
> This problem is in curator-discovery module where we get an NPE on 
> ServiceProvider.start() because child.getData() can be null while starting 
> ServiceCacheImpl. This is similar to 
> https://issues.apache.org/jira/browse/CURATOR-452 but happens on adding null 
> to map.
> *NPE Stacktrace*
> {{java.lang.NullPointerException at 
> java.util.concurrent.ConcurrentHashMap.putVal(ConcurrentHashMap.java:1011) 
> ~[?:1.8.0_112] at 
> java.util.concurrent.ConcurrentHashMap.putIfAbsent(ConcurrentHashMap.java:1535)
>  ~[?:1.8.0_112] at 
> org.apache.curator.x.discovery.details.ServiceCacheImpl.addInstance(ServiceCacheImpl.java:196)
>  ~[curator-x-discovery-4.0.0.jar:?] at 
> org.apache.curator.x.discovery.details.ServiceCacheImpl.start(ServiceCacheImpl.java:96)
>  ~[curator-x-discovery-4.0.0.jar:?] at 
> org.apache.curator.x.discovery.details.ServiceProviderImpl.start(ServiceProviderImpl.java:75)
>  ~[curator-x-discovery-4.0.0.jar:?]}}
> *The code*
> {{client = CuratorFrameworkFactory.newClient("localhost:2181", new 
> ExponentialBackoffRetry(1000, 3));}}
> {{client.start();}}
> {{serviceDiscovery = 
> ServiceDiscoveryBuilder.builder(ServiceRecord.class).client(client).basePath("/discovery/services/").serializer(serializer).build();
>  serviceDiscovery.start();}}
> {{serviceProvider = 
> serviceDiscovery.serviceProviderBuilder().serviceName(serviceName).build();}}
> {{serviceProvider.start();}}

This message was sent by Atlassian JIRA

Reply via email to