From 3b5e6ce068a4d08f08c6df053f63a3d33419b676 Mon Sep 17 00:00:00 2001 From: Cheng Pan Date: Wed, 27 Jul 2022 13:34:09 +0800 Subject: [PATCH] fix npe --- .../apache/kyuubi/jdbc/hive/KyuubiConnection.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) 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 253a04759f0..770ba344840 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 @@ -124,7 +124,6 @@ public static List getAllUrls(String zookeeperBasedHS2Url) } public KyuubiConnection(String uri, Properties info) throws SQLException { - setupTimeout(); try { connParams = Utils.parseURL(uri, info); } catch (ZooKeeperHiveClientException e) { @@ -140,6 +139,7 @@ public KyuubiConnection(String uri, Properties info) throws SQLException { host = Utils.getCanonicalHostName(connParams.getHost()); port = connParams.getPort(); sessConfMap = connParams.getSessionVars(); + setupTimeout(); if (sessConfMap.containsKey(FETCH_SIZE)) { fetchSize = Integer.parseInt(sessConfMap.get(FETCH_SIZE)); @@ -868,24 +868,22 @@ private String getSessionValue(String varName, String varDefault) { private void setupTimeout() { if (sessConfMap.containsKey(CONNECT_TIMEOUT)) { - long connectTimeoutMs = 0; - String loginTimeoutStr = getSessionValue(CONNECT_TIMEOUT, "0"); + String loginTimeoutStr = sessConfMap.get(CONNECT_TIMEOUT); try { - connectTimeoutMs = Long.parseLong(loginTimeoutStr); + long connectTimeoutMs = Long.parseLong(loginTimeoutStr); + connectTimeout = (int) Math.max(0, Math.min(connectTimeoutMs, Integer.MAX_VALUE)); } catch (NumberFormatException e) { LOG.info("Failed to parse connectTimeout of value " + loginTimeoutStr); } - connectTimeout = (int) Math.max(0, Math.min(connectTimeoutMs, Integer.MAX_VALUE)); } if (sessConfMap.containsKey(SOCKET_TIMEOUT)) { - long socketTimeoutMs = 0; String socketTimeoutStr = sessConfMap.get(SOCKET_TIMEOUT); try { - socketTimeoutMs = Long.parseLong(socketTimeoutStr); + long socketTimeoutMs = Long.parseLong(socketTimeoutStr); + socketTimeout = (int) Math.max(0, Math.min(socketTimeoutMs, Integer.MAX_VALUE)); } catch (NumberFormatException e) { LOG.info("Failed to parse socketTimeout of value " + socketTimeoutStr); } - socketTimeout = (int) Math.max(0, Math.min(socketTimeoutMs, Integer.MAX_VALUE)); } }