This is an automated email from the ASF dual-hosted git repository.

yuqi4733 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gravitino.git


The following commit(s) were added to refs/heads/main by this push:
     new 4249993aa Fix potential NullPointerException in UserContext by adding 
null check for parentContext. (#4348)
4249993aa is described below

commit 4249993aa868ba1f91eca663be696432d82a29ac
Author: kartik <[email protected]>
AuthorDate: Wed Aug 7 15:14:12 2024 +0530

    Fix potential NullPointerException in UserContext by adding null check for 
parentContext. (#4348)
    
    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.
---
 .../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);

Reply via email to