BetterCloud / vault-java-driver

Zero-dependency Java client for HashiCorp's Vault
https://bettercloud.github.io/vault-java-driver/
334 stars 224 forks source link

Caused by: java.lang.NullPointerException: null at com.bettercloud.vault.rest.Rest.responseBodyBytes(Rest.java:519) #253

Open brycechesternewman opened 1 year ago

brycechesternewman commented 1 year ago

Hello. We are using vault-java-driver 5.1.0.

Sometimes we are seeing this NPE.

  com.bettercloud.vault.VaultException: java.lang.NullPointerException
    at com.bettercloud.vault.api.Auth.loginByAwsIam(Auth.java:913)
    ...
Caused by: java.lang.NullPointerException: null
    at com.bettercloud.vault.rest.Rest.responseBodyBytes(Rest.java:519)
    at com.bettercloud.vault.rest.Rest.postOrPutImpl(Rest.java:413)
    at com.bettercloud.vault.rest.Rest.post(Rest.java:306)
    at com.bettercloud.vault.api.Auth.loginByAwsIam(Auth.java:886)
    ... 21 common frames omitted

In Rest.java at line 519 the inputStream is null.

...
            while ((bytesRead = inputStream.read(bytes, 0, bytes.length)) != -1) {
                byteArrayOutputStream.write(bytes, 0, bytesRead);
            }
...

The null needs to be handled since HttpURLConnection.java can return null.

 public InputStream getErrorStream() {
        return null;
    }