oracle / oci-java-sdk

Oracle Cloud Infrastructure SDK for Java
https://cloud.oracle.com/cloud-infrastructure
Other
192 stars 152 forks source link

Misleading exception when endpoint isn't configured. java.lang.NullPointerException: "this.httpClient" is null #589

Open e3ndr opened 2 months ago

e3ndr commented 2 months ago

This is a low-priority issue, but when calling the API without an endpoint the SDK appears to not be configuring the http client, rather than throwing an error early-on informing the user that an endpoint is required. This only occurs on 3.x, 2.x properly throws an error for the missing endpoint early-on.

Code to reproduce:

        this.containerClient = ContainerInstanceClient
            .builder()
            // .endpoint("https://compute-containers.us-ashburn-1.oci.oraclecloud.com") // Omit to reproduce.
            .build(provider);

        // Call any API now.

Stacktrace:

Caused by: java.lang.NullPointerException: Cannot invoke "com.oracle.bmc.http.client.HttpClient.createRequest(com.oracle.bmc.http.client.Method)" because "this.httpClient" is null
    at com.oracle.bmc.http.internal.ClientCall.method(ClientCall.java:173)
    at com.oracle.bmc.containerinstances.ContainerInstanceClient.createContainerInstance(ContainerInstanceClient.java:202)
    ... 5 more

It should also be noted that the Oracle docs that give the SDK copy/paste examples don't tell you that you need to configure the endpoint.