[
https://issues.apache.org/jira/browse/CURATOR-452?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16700922#comment-16700922
]
ASF GitHub Bot commented on CURATOR-452:
----------------------------------------
Github user cmckn commented on the issue:
https://github.com/apache/curator/pull/261
I realize this issue has been closed, but I'm still seeing unexpected
exceptions in some of my applications during `ServiceCacheImpl#start`.
The merged changes to address this added a null-check around calls to
`ServiceCacheImpl#addInstance` within `ServiceCacheImpl#start` (correct me if
this is wrong).
From what I've seen in my own apps, the issue is not caused by a `null`
`char[]` being passed to `ServiceCacheImpl#addInstance` -- it is caused by an
*empty* `char[]` being passed. This empty array causes a `NullPointerException`
to be thrown by my deserializer, or (if the empty case is handled there,
returning `null` from the deserializer) causes a `NullPointerException` when
the `null` instance is put in `instances` (a `ConcurrentMap`).
The implementation of `ServiceCacheImpl#addInstance` below is what resolved
things for me, patched into the `4.0.1` release. The `if` at the open of the
function is the only change. Just wanted to throw this out there, because I've
only been able to resolve the issue by using this patch -- no dice on the
current `master` branch. This patch doesn't appear to cause any issues, but I'm
not sure if the `cache.clearDataBytes...` call should be performed regardless
of whether or not the `byte[]` is empty (i.e. I'm not sure if bailing out of
the function at this particular step is appropriate or will have side-effects).
```
private void addInstance(ChildData childData, boolean onlyIfAbsent) throws
Exception
{
+ if( childData.getData() == null || childData.getData().length
== 0 )
+ {
+ return;
+ }
String instanceId = instanceIdFromData(childData);
ServiceInstance<T> serviceInstance =
discovery.getSerializer().deserialize(childData.getData());
if ( onlyIfAbsent )
{
instances.putIfAbsent(instanceId, serviceInstance);
}
else
{
instances.put(instanceId, serviceInstance);
}
cache.clearDataBytes(childData.getPath(),
childData.getStat().getVersion());
}
```
Happy to provide more information if needed.
> ChildData.getData() can be null
> -------------------------------
>
> Key: CURATOR-452
> URL: https://issues.apache.org/jira/browse/CURATOR-452
> Project: Apache Curator
> Issue Type: Bug
> Components: Client
> Affects Versions: 2.11.1
> Reporter: Egor Ryashin
> Assignee: Jordan Zimmerman
> Priority: Critical
> Fix For: 4.1.0
>
>
> Curator client tries to make ObjectMapper to parse null (ChildData.getData()
> can be null).
> {code:java}
> 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){code}
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)