danhuawang opened a new issue, #11365:
URL: https://github.com/apache/gravitino/issues/11365
### Version
main branch
### Describe what's wrong
When using the Gravitino Trino connector with OAuth2 authentication
(`gravitino.client.authType=oauth2`), the connector throws a
`NullPointerException` with the message `"Endpoint"` during the scheduled
metalake loading process. The NPE originates from Apache HC5's
`URIAuthority.<init>` when the HTTP client attempts to execute a request to the
Gravitino server.
The connector starts successfully and logs `"Gravitino
CatalogConnectorManager started."`, but the subsequent scheduled metalake
loading fails repeatedly with this unhandled NPE. The error message is
unhelpful and does not indicate whether the root cause is a DNS resolution
failure, a network connectivity issue, or a malformed URI.
The Gravitino client's `HTTPClient.execute()` does not properly handle this
edge case from the underlying Apache HC5 library, resulting in an opaque NPE
instead of a meaningful error message (e.g., "Cannot resolve host" or "Failed
to establish connection to endpoint").
### Error message and/or stacktrace
```
2026-06-02 11:12:37 ERROR [gravitino-connector-schedule-0]
CatalogConnectorManager:193 - Error when loading metalake
java.lang.NullPointerException: Endpoint
at java.base/java.util.Objects.requireNonNull(Objects.java:246)
at org.apache.hc.core5.util.Args.notNull(Args.java:165)
at org.apache.hc.core5.net.URIAuthority.<init>(URIAuthority.java:130)
at org.apache.hc.core5.net.URIAuthority.<init>(URIAuthority.java:136)
at
org.apache.hc.client5.http.impl.classic.InternalHttpClient.doExecute(InternalHttpClient.java:168)
at
org.apache.hc.client5.http.impl.classic.CloseableHttpClient.execute(CloseableHttpClient.java:123)
at org.apache.gravitino.client.HTTPClient.execute(HTTPClient.java:369)
at org.apache.gravitino.client.HTTPClient.execute(HTTPClient.java:296)
at org.apache.gravitino.client.HTTPClient.get(HTTPClient.java:465)
at org.apache.gravitino.client.RESTClient.get(RESTClient.java:165)
at
org.apache.gravitino.client.GravitinoClientBase.serverVersion(GravitinoClientBase.java:178)
at
org.apache.gravitino.client.GravitinoClientBase.checkVersion(GravitinoClientBase.java:103)
at
org.apache.gravitino.client.HTTPClient.performPreConnectHandler(HTTPClient.java:420)
at org.apache.gravitino.client.HTTPClient.execute(HTTPClient.java:342)
at org.apache.gravitino.client.HTTPClient.execute(HTTPClient.java:296)
at org.apache.gravitino.client.HTTPClient.get(HTTPClient.java:465)
at org.apache.gravitino.client.RESTClient.get(RESTClient.java:165)
at
org.apache.gravitino.client.GravitinoClientBase.loadMetalake(GravitinoClientBase.java:134)
at
org.apache.gravitino.trino.connector.catalog.CatalogConnectorManager.retrieveMetalake(CatalogConnectorManager.java:206)
at
java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1724)
at
org.apache.gravitino.trino.connector.catalog.CatalogConnectorManager.loadMetalake(CatalogConnectorManager.java:174)
at
java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:545)
at
java.base/java.util.concurrent.FutureTask.runAndReset(FutureTask.java:369)
at
java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:310)
at
java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1090)
at
java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:614)
at java.base/java.lang.Thread.run(Thread.java:1474)
```
### How to reproduce
1. Deploy the Gravitino Trino connector with OAuth2 authentication in a
Kubernetes environment.
2. Configure `gravitino.properties` with the following settings:
```properties
connector.name=gravitino
gravitino.uri=http://gravitino.gravitino-e2e-env2-oauth2-auth.svc.cluster.local:9090
gravitino.metalake=test
gravitino.client.authType=oauth2
gravitino.client.oauth2.serverUri=http://192.168.97.2:30080
gravitino.client.oauth2.credential=<client_id>:<client_secret>
gravitino.client.oauth2.path=/realms/myrealm/protocol/openid-connect/token
gravitino.client.oauth2.scope=openid profile email
```
3. Start the Trino server. The connector initializes successfully.
4. Wait for the scheduled metalake loading (10 seconds interval). The
`CatalogConnectorManager` throws the NPE repeatedly.
The issue may be triggered when:
- The Gravitino server host cannot be resolved via DNS, OR
- The HTTP route/endpoint cannot be determined by Apache HC5 for other
reasons (e.g., network unreachable)
### Additional context
- The NPE is thrown by Apache HC5
(`org.apache.hc.client5.http.impl.classic.InternalHttpClient.doExecute`) when
it cannot determine the target endpoint (host) for the request.
- `HTTPClient.execute()` in `gravitino/clients/client-java` does not catch
or wrap this NPE, so the error message `"Endpoint"` is unhelpful for debugging.
- A suggested fix would be to catch the NPE in `HTTPClient.execute()` and
wrap it in a `RESTException` with a meaningful message indicating the target
URI and the likely cause (DNS resolution failure or invalid endpoint).
- Alternatively, validate that the URI is resolvable before attempting the
HTTP call, or use HC5's `HttpClientBuilder` with a custom `HttpRoutePlanner`
that provides better error handling.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]