Skip to content

Trino Gravitino connector throws NullPointerException #11365 - #11426

Merged
diqiu50 merged 5 commits into
apache:mainfrom
Octavi00:main
Jun 10, 2026
Merged

Trino Gravitino connector throws NullPointerException #11365#11426
diqiu50 merged 5 commits into
apache:mainfrom
Octavi00:main

Conversation

@Octavi00

@Octavi00 Octavi00 commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

Added specific exception handling to avoid previous bland nullptr exceptions.

Why are the changes needed?

  1. Allows earlier issue catching (URI syntax tested before http execution)
  2. Adds depth to exceptions by specifying common exceptions. Added: UnknownHostException, ConnectException, IOException, NullPointerException, and default Exception to preserve unexpected failures.

Fix: #11365

Does this PR introduce any user-facing change?

No

How was this patch tested?

Added two unit tests to prove the specific exceptions' behavior.

IMPORTANT: since the bug fix was considered urgent, and I have no previous Kubernetes environment, I chose to utilize unit tests to replicate common exceptions that would allow me to create specific cases for such.

  • All client tests passed

Octavi00 and others added 3 commits June 3, 2026 22:41
… to provide more context in error messages. Updated catch blocks to include the request URI aswell for better debugging.
@mchades
mchades requested a review from diqiu50 June 5, 2026 02:58

@diqiu50 diqiu50 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should focus on finding the root cause of the issue, instead of just handling the NPE.

@jerryshao
jerryshao requested a review from diqiu50 June 5, 2026 03:29
@github-actions

github-actions Bot commented Jun 5, 2026

Copy link
Copy Markdown

Code Coverage Report

Overall Project 66.93% +0.02% 🟢
Files changed 75.0% 🟢

Module Coverage
aliyun 1.72% 🔴
api 46.82% 🟢
authorization-common 85.96% 🟢
aws 3.66% 🔴
azure 2.47% 🔴
catalog-common 10.4% 🔴
catalog-fileset 80.23% 🟢
catalog-glue 66.72% 🟢
catalog-hive 79.44% 🟢
catalog-jdbc-clickhouse 80.02% 🟢
catalog-jdbc-common 44.22% 🟢
catalog-jdbc-doris 80.28% 🟢
catalog-jdbc-hologres 54.03% 🟢
catalog-jdbc-mysql 79.23% -2.76% 🟢
catalog-jdbc-oceanbase 78.38% 🟢
catalog-jdbc-postgresql 82.29% 🟢
catalog-jdbc-starrocks 78.51% 🟢
catalog-kafka 77.01% 🟢
catalog-lakehouse-generic 58.53% 🟢
catalog-lakehouse-hudi 79.1% 🟢
catalog-lakehouse-iceberg 85.79% 🟢
catalog-lakehouse-paimon 79.15% 🟢
catalog-model 77.72% 🟢
cli 44.51% 🟢
client-java 78.02% +0.24% 🟢
common 49.9% 🟢
core 82.38% 🟢
filesystem-hadoop3 77.27% 🟢
flink 0.0% 🔴
flink-common 45.72% 🟢
flink-runtime 0.0% 🔴
gcp 14.12% 🔴
hadoop-common 10.39% 🔴
hive-metastore-common 53.9% 🟢
iceberg-common 57.41% 🟢
iceberg-rest-server 73.69% 🟢
idp-basic 86.18% 🟢
integration-test-common 0.0% 🔴
jobs 66.17% 🟢
lance-common 20.81% 🔴
lance-rest-server 60.54% 🟢
lineage 53.02% 🟢
optimizer 82.87% 🟢
optimizer-api 21.95% 🔴
server 85.73% 🟢
server-common 73.28% 🟢
spark 28.57% 🔴
spark-common 41.16% 🟢
trino-connector 40.13% 🟢
Files
Module File Coverage
catalog-jdbc-mysql MysqlColumnDefaultValueConverter.java 37.14% 🔴
client-java HTTPClient.java 82.66% 🟢

@Octavi00

Octavi00 commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

@diqiu50 Alright, no problem. I will take a deeper dive into it. I had previously assumed it was just unhandled edge cases as listed in the description, but I will spend more time reproducing and testing the given method over the weekend, and I will get back to you about my progress on Monday Afternoon.

…nd the error to lie in the buildURI method of the HTTPClient class. The method is not properly handling the case where the server URI is invalid, which leads to a NullPointerException when it tries to build the request URI. I have added a check for null and throw an IllegalArgumentException with a more descriptive message when the server URI is invalid. This should help in identifying the issue more clearly in the future.
@Octavi00

Octavi00 commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

@diqiu50 I spent some time revisiting the bug report and came to the conclusion it was due to an overly simple buildUri function inside of HTTPClient.java.

I came to this conclusion by first acknowledging the fact that the issue happens after the CatalogConnectorManager starts, not before. So, in order to jump to DefaultOAuth2TokenProvider, which, after testing, worked fine, I went to GravitinoAuthProvider, which was alright as well. Then I moved to the scheduled path, and followed until I found a path for possible error:
start() -> loadMetalake() -> retrieveMetalake() -> GravitinoClientBase.loadMetalake() -> restClient.get() -> HTTPClient.execute().

Within HTTPClient.execute() I found room for error. I saw that the argument request, the parameter within the call, was built from buildUri() within the file. I then scrolled to the buildUri() function and found it was only manually joining the parameters uri and path using the String.format() function, then simply returning it. So it was an unchecked URI that was then passed to HC5, which could return an NPE.

My fix was to first validate the URI by making a separate URI variable requestUri, and building it. If its required properties were still null, scheme or host, then I would throw a RESTException stating such, otherwise I'd return it as expected. I didn't change the manually joining parameters to preserve already existing tests and code flow, while still addressing the issue. I also added one more unit test to ensure an invalid URI is handled before the execution, as was the issue I observed.

Importantly, I haven't had the time to create my own Kubernetes environment to perfectly replicate the bug, as I'm newer to this repository, but I feel that I was correctly following the bug's trail, and I'm pretty confident in my solution. It'd be great if someone with the particular environment could test my proposal.

Thank you

- Use buildUri() result directly as requestUri instead of calling
  request.getUri() afterwards, which was both roundabout and declared
  an unreachable URISyntaxException catch block
- Remove the NullPointerException catch that matched on HC5's internal
  string literal "Endpoint"; buildUri() already validates scheme and
  host are non-null, so HC5 will always have a valid authority set on
  the request and cannot reach that code path
@diqiu50

diqiu50 commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

@Octavi00 Thanks for your contribution. Your fix looks good. I removed some dead code.

@diqiu50 diqiu50 added the branch-1.3 Automatically cherry-pick commit to branch-1.3 label Jun 10, 2026

@diqiu50 diqiu50 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@diqiu50
diqiu50 merged commit 732adb1 into apache:main Jun 10, 2026
31 checks passed
jerryshao pushed a commit that referenced this pull request Jun 11, 2026
…terException #11365 (#11426) (#11562)

**Cherry-pick Information:**
- Original commit: 732adb1
- Target branch: `branch-1.3`
- Status: ✅ Clean cherry-pick (no conflicts)

Co-authored-by: Octavio Herrera Contreras <156601957+Octavi00@users.noreply.github.com>
Co-authored-by: yuhui <hui@datastrato.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

branch-1.3 Automatically cherry-pick commit to branch-1.3

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug report] Trino Gravitino connector throws NullPointerException "Endpoint" when loading metalake with OAuth2 auth

2 participants