question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NPE in zookeeperdiscoveryclient when instance-port not specified

See original GitHub issue

I am seeing a strange NPE in ZKDC when the client is accessed first time to load the list of service instances:

java.lang.NullPointerException: null
	at org.springframework.cloud.zookeeper.discovery.ZookeeperDiscoveryClient.getInstances(ZookeeperDiscoveryClient.java:89)

It seems that under certain conditions, ZookeeperServiceDiscovery.build() is never called - and the bulk of init work is being done there. After adding the property spring.cloud.zookeeper.discovery.instance-port the npe went away. The instance-port property is optional though, it should default to the listen port.

Note that the only other zookeeper related property i am using is spring.cloud.zookeeper.connect-string

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jorgheymanscommented, Jan 27, 2017

Version 1.0.3, the only config property I had defined was the zookeeper connection string.

0reactions
lurongjiangcommented, Nov 3, 2021

@spencergibb Thanks.I found out why it didn’t work in my project.I debugger and get the byte for path from curator client,the data:

{
  "payload": {
    "@class": "org.springframework.cloud.zookeeper.discovery.ZookeeperInstance",
    "metadata": {
      "groupId": "WGQ",
      "role": "TestApp-LRJ",
      "instance_status": "UP"
    },
    "name": "TestApp",
    "id": "TestApp-1"
  },
  "registrationTimeUTC": 1635852567130,
  "serviceType": "DYNAMIC",
  "sslPort": null,
  "uriSpec": {
    "parts": [
      {
        "variable": true,
        "value": "scheme"
      },
      {
        "variable": false,
        "value": "://"
      },
      {
        "variable": true,
        "value": "address"
      },
      {
        "variable": false,
        "value": ":"
      },
      {
        "variable": true,
        "value": "port"
      }
    ]
  },
  "address": "localhost",
  "name": "TestApp",
  "id": "TestApp-1",
  "port": 8086
}

then I tried to deserialize the data to ZookeeperInstance,the code

public class TestDeserialize {
    public static void main(String[] args) throws Exception {
        Path path = Paths.get(args[0]);
        byte[] bytes = Files.readAllBytes(path);
        JsonInstanceSerializer<ZookeeperInstance> serializer = new JsonInstanceSerializer<>(ZookeeperInstance.class);
        ServiceInstance<ZookeeperInstance> instanceServiceInstance = serializer.deserialize(bytes);
        System.out.println(instanceServiceInstance.getName());
    }
}

then I got the json string

{"name":"","id":"","address":null,"port":null,"sslPort":null,"payload":null,"registrationTimeUTC":0,"serviceType":"DYNAMIC","uriSpec":null,"enabled":true}

then I found the ObejctMapper was from org.codehaus.jackson:jackson-mapper-asl:1.8.8.

I realized that it might be a dependency omit problem.I exclude the jackson from hadoop, then it work

<dependency>
    <groupId>org.apache.hadoop</groupId>
    <artifactId>hadoop-yarn-client</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>*</artifactId>
        </exclusion>
    </exclusions>
</dependency>

It just was a bug in my code.Thank for your reply.

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found