spring-cloud / spring-cloud/spring-cloud-zookeeper
NullPointerException for ZookeeperAutoServiceRegistration
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 574
- Forks
- 408
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 4
Description
ZookeeperAutoServiceRegistration throws an exception when ServiceInstanceRegistration method getServiceInstance() is called before ZookeeperAutoServiceRegistration method getPort()
It happens because method getServiceInstance() calls build() and when getPort() will be called it will return null instead 0.
https://github.com/spring-cloud/spring-cloud-zookeeper/blob/ec845a47a00d560e6cf234a342fd31614823a20c/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/serviceregistry/ServiceInstanceRegistration.java#L64-L69
https://github.com/spring-cloud/spring-cloud-zookeeper/blob/ec845a47a00d560e6cf234a342fd31614823a20c/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/serviceregistry/ServiceInstanceRegistration.java#L71-L73
https://github.com/spring-cloud/spring-cloud-zookeeper/blob/ec845a47a00d560e6cf234a342fd31614823a20c/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/serviceregistry/ServiceInstanceRegistration.java#L83-L88
https://github.com/spring-cloud/spring-cloud-zookeeper/blob/ec845a47a00d560e6cf234a342fd31614823a20c/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/serviceregistry/ZookeeperAutoServiceRegistration.java#L70-L79
Also getInstanceId() method returns null.
Use case when we need to call getServiceInstance for example to create leader candidate and associate with registration id for further understanding which node is a leader.
@Bean
public DefaultCandidate bean(ServiceInstanceRegistration registration) {
return return new DefaultCandidate(registration.getServiceInstance().getId(), "default");
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading ServiceInstanceRegistration.java and ZookeeperAutoServiceRegistration.java at the linked methods, then trace the call order where getServiceInstance() runs before getPort(). Verify the registration can be obtained in that order without a NullPointerException, with a usable port and non-null instance ID.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring-boot
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100