cloudant / java-cloudant

A Java client for Cloudant
Apache License 2.0
79 stars 68 forks source link

Wrong password gets null pointer exception from serverVersion() #476

Closed Kenzku closed 5 years ago

Kenzku commented 5 years ago

Please read these guidelines before opening an issue.

Bug Description

1. Steps to reproduce and the simplest code sample possible to demonstrate the issue

/*give a wrong password*/
CloudantClient client = ClientBuilder.url(new URL(url))
                    .username(user)
                    .password(password)
                    .build();

try {
      String version = client.serverVersion();
      // or client.createDB("TEST"); etc
    } catch (CouchDbException e) {
     /*Method threw 'java.lang.NullPointerException' exception. Cannot evaluate com.cloudant.client.org.lightcouch.CouchDbException.toString()*/
      logger.error(e.getMessage());
}

2. What you expected to happen

Shall catch unauthorised error

3. What actually happened

Method threw 'java.lang.NullPointerException' exception. Cannot evaluate com.cloudant.client.org.lightcouch.CouchDbException.toString()

Environment details

looks like somewhere the in highlight below, gets null, and passed down to the super(message)

screenshot 2019-02-14 at 15 23 29 screenshot 2019-02-14 at 15 23 55 screenshot 2019-02-14 at 15 24 08
ricellis commented 5 years ago

If you call client.serverVersion() against CouchDB or Cloudant with an incorrect password then you will get a successful response without a CouchDbException because the server information (root endpoint) is not protected.

What type of server are you running against?

I can't see how you can get a NullPointerException from your example because you'll never end up in the catch block. In your real code are you assigning the exception to a field and then calling toString() on it and therefore in the server version case ending up with a NPE?

Kenzku commented 5 years ago

did you try to give a wrong password?

Kenzku commented 5 years ago

In your real code are you assigning the exception to a field and then calling toString() on it and therefore in the server version case ending up with a NPE?

That NPE is from your code

If you call client.serverVersion() against CouchDB or Cloudant with an incorrect password then you will get a successful response without a CouchDbException because the server information (root endpoint) is not protected.

I can call client.createDB("TEST") and get the same result

ricellis commented 5 years ago

It seems that perhaps the error/reason is missing from the response body, which I think would be a server side problem.

ricellis commented 5 years ago

I took another look at this and neither the server returning an empty body nor null error/reason responses causes a NPE in the CouchDbException code. Are you able to provide the full stack trace of the NPE?