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

chengpan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kyuubi.git


The following commit(s) were added to refs/heads/master by this push:
     new e4ecde2c1 [KYUUBI #6396][FOLLOWUP] Avoid NPE
e4ecde2c1 is described below

commit e4ecde2c1d90b4c50b8794024cef44ec05300eda
Author: wforget <[email protected]>
AuthorDate: Mon May 27 06:31:39 2024 +0000

    [KYUUBI #6396][FOLLOWUP] Avoid NPE
    
    # :mag: Description
    ## Issue References ๐Ÿ”—
    
    This pull request fixes #6396
    
    ## Describe Your Solution ๐Ÿ”ง
    
    NPE will occur when kyuubiClientTicketCache is not specified. 
`ConcurrentHashMap` does not allow null key.
    
    ## Types of changes :bookmark:
    
    - [X] Bugfix (non-breaking change which fixes an issue)
    - [ ] New feature (non-breaking change which adds functionality)
    - [ ] Breaking change (fix or feature that would cause existing 
functionality to change)
    
    ## Test Plan ๐Ÿงช
    
    #### Behavior Without This Pull Request :coffin:
    
    #### Behavior With This Pull Request :tada:
    
    #### Related Unit Tests
    
    ---
    
    # Checklist ๐Ÿ“
    
    - [x] This patch was not authored or co-authored using [Generative 
Tooling](https://www.apache.org/legal/generative-tooling.html)
    
    **Be nice. Be informative.**
    
    Closes #6420 from wForget/hotfix2.
    
    Closes #6396
    
    e5d5f9d33 [wforget] address comment
    fe9ecd1b1 [wforget] Avoid NPE
    
    Authored-by: wforget <[email protected]>
    Signed-off-by: Cheng Pan <[email protected]>
---
 .../src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiConnection.java    | 2 +-
 .../apache/kyuubi/jdbc/hive/auth/KerberosAuthenticationManager.java    | 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git 
a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiConnection.java
 
b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiConnection.java
index 8b6c8f50d..16347771d 100644
--- 
a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiConnection.java
+++ 
b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiConnection.java
@@ -930,7 +930,7 @@ public class KyuubiConnection implements SQLConnection, 
KyuubiLoggable {
       AccessControlContext context = AccessController.getContext();
       return Subject.getSubject(context);
     } else if (isTgtCacheAuthMode()) {
-      String ticketCache = sessConfMap.get(AUTH_KYUUBI_CLIENT_TICKET_CACHE);
+      String ticketCache = 
sessConfMap.getOrDefault(AUTH_KYUUBI_CLIENT_TICKET_CACHE, "");
       return 
KerberosAuthenticationManager.getTgtCacheAuthentication(ticketCache).getSubject();
     } else {
       // This should never happen
diff --git 
a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/auth/KerberosAuthenticationManager.java
 
b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/auth/KerberosAuthenticationManager.java
index 6a639c7d6..065b6a295 100644
--- 
a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/auth/KerberosAuthenticationManager.java
+++ 
b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/auth/KerberosAuthenticationManager.java
@@ -17,6 +17,8 @@
 
 package org.apache.kyuubi.jdbc.hive.auth;
 
+import static java.util.Objects.requireNonNull;
+
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
@@ -29,6 +31,7 @@ public class KerberosAuthenticationManager {
       new ConcurrentHashMap<>();
 
   public static CachingKerberosAuthentication getTgtCacheAuthentication(String 
ticketCache) {
+    requireNonNull(ticketCache, "ticketCache is null");
     return TGT_CACHE_AUTHENTICATION_CACHE.computeIfAbsent(
         ticketCache,
         key -> {

Reply via email to