Skip to content

NullPointerException for ZookeeperAutoServiceRegistration #310

Description

@ivan-zaitsev

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.

public ServiceInstance<ZookeeperInstance> getServiceInstance() {
if (this.serviceInstance == null) {
build();
}
return this.serviceInstance;
}


public int getPort() {
if (this.serviceInstance == null) {
return 0;
}
return this.serviceInstance.getPort();
}

protected void register() {
if (!this.properties.isRegister()) {
log.debug("Registration disabled.");
return;
}
if (this.registration.getPort() == 0) {
this.registration.setPort(getPort().get());
}
super.register();
}

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");
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions