From 35088ca827e29b109a2b692ca9da13fa77d97d04 Mon Sep 17 00:00:00 2001 From: Mark Zitnik Date: Mon, 28 Oct 2024 18:59:32 +0200 Subject: [PATCH] Protect from ArrayIndexOutOfBoundsException exception when extracting values for user agent. (#360) --- .../com/clickhouse/spark/client/NodeClient.scala | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/clickhouse-core/src/main/scala/com/clickhouse/spark/client/NodeClient.scala b/clickhouse-core/src/main/scala/com/clickhouse/spark/client/NodeClient.scala index 0d777d95..81c485a6 100644 --- a/clickhouse-core/src/main/scala/com/clickhouse/spark/client/NodeClient.scala +++ b/clickhouse-core/src/main/scala/com/clickhouse/spark/client/NodeClient.scala @@ -45,12 +45,16 @@ class NodeClient(val nodeSpec: NodeSpec) extends AutoCloseable with Logging { private lazy val userAgent = { val title = getClass.getPackage.getImplementationTitle val version = getClass.getPackage.getImplementationVersion - if (version != null) { + if (version != null && title != null) { val versions = version.split("_") - val sparkVersion = versions(0) - val scalaVersion = versions(1) - val connectorVersion = versions(2) - s"${title}/${connectorVersion} (fv:spark/${sparkVersion}, lv:scala/${scalaVersion})" + if (versions.length < 3) { + "Spark-ClickHouse-Connector" + } else { + val sparkVersion = versions(0) + val scalaVersion = versions(1) + val connectorVersion = versions(2) + s"${title}/${connectorVersion} (fv:spark/${sparkVersion}, lv:scala/${scalaVersion})" + } } else { "Spark-ClickHouse-Connector" }