This is an automated email from the ASF dual-hosted git repository.
yuqi4733 pushed a commit to branch branch-0.6
in repository https://gitbox.apache.org/repos/asf/gravitino.git
The following commit(s) were added to refs/heads/branch-0.6 by this push:
new 62aa8fbe3 [#4331] fix(catalog-hadoop): Fix potential
NullPointerException in UserContext by adding null check for parentContext.
(#4418)
62aa8fbe3 is described below
commit 62aa8fbe3062a4a3131270177b34f6e4f340aed8
Author: github-actions[bot]
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Wed Aug 7 19:01:22 2024 +0800
[#4331] fix(catalog-hadoop): Fix potential NullPointerException in
UserContext by adding null check for parentContext. (#4418)
Title: [#4331] fix: add null check for parentContext in UserContext
### What changes were proposed in this pull request?
This pull request adds a null check for the parentContext variable in
the getUserContext method of UserContext.java. This ensures that a
NullPointerException is avoided when deepCopy() is called on
parentContext.
### Why are the changes needed?
The change is needed to prevent a potential NullPointerException if
parentContext is null. Adding this check makes the code more reliable.
Fix: #4331
### Does this PR introduce _any_ user-facing change?
No, this change does not introduce any user-facing changes.
### How was this patch tested?
The change was reviewed to ensure that the null check effectively
prevents the issue. No new tests were needed, as this is a preventive
fix.
Co-authored-by: kartik <[email protected]>
---
.../org/apache/gravitino/catalog/hadoop/authentication/UserContext.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git
a/catalogs/catalog-hadoop/src/main/java/org/apache/gravitino/catalog/hadoop/authentication/UserContext.java
b/catalogs/catalog-hadoop/src/main/java/org/apache/gravitino/catalog/hadoop/authentication/UserContext.java
index 1023be45f..3bf84adbb 100644
---
a/catalogs/catalog-hadoop/src/main/java/org/apache/gravitino/catalog/hadoop/authentication/UserContext.java
+++
b/catalogs/catalog-hadoop/src/main/java/org/apache/gravitino/catalog/hadoop/authentication/UserContext.java
@@ -125,7 +125,7 @@ public abstract class UserContext implements Closeable {
} else if (authenticationType == AuthenticationType.KERBEROS) {
// if the kerberos authentication is inherited from the parent context,
we will use the
// parent context's kerberos configuration.
- if (authenticationConfig.isSimpleAuth()) {
+ if (parentContext != null && authenticationConfig.isSimpleAuth()) {
KerberosUserContext kerberosUserContext = ((KerberosUserContext)
parentContext).deepCopy();
kerberosUserContext.setEnableUserImpersonation(enableUserImpersonation);
addUserContext(nameIdentifier, kerberosUserContext);