From 7d93267727aa963783a79845e00c1f8fbc2cc369 Mon Sep 17 00:00:00 2001 From: hezhao2 Date: Thu, 11 Apr 2024 19:02:48 +0800 Subject: [PATCH] [KYUUBI #6291] Avoid NPE in MySQLErrPacket MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # :mag: Description as title ## Issue References ๐Ÿ”— This pull request fixes #6291 ## Describe Your Solution ๐Ÿ”ง Add a rule to check if it's null ## 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 #6292 from zhaohehuhu/dev-0411. Closes #6291 a58eed609 [hezhao2] refactor 40ad5e0fa [hezhao2] Avoid NPE in MySQLErrPacket e02be17b4 [dupeng] [KYUUBI #6288] [KYUUBI #6283] Improve the message of distribution built without enabling web ui Lead-authored-by: hezhao2 Co-authored-by: dupeng Signed-off-by: Cheng Pan (cherry picked from commit f43cc593c3bb67ba6f678ce32ba74da0aa7c4f56) Signed-off-by: Cheng Pan --- .../org/apache/kyuubi/server/mysql/MySQLGenericPackets.scala | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kyuubi-server/src/main/scala/org/apache/kyuubi/server/mysql/MySQLGenericPackets.scala b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/mysql/MySQLGenericPackets.scala index f378bc0a09a..946e9c313f8 100644 --- a/kyuubi-server/src/main/scala/org/apache/kyuubi/server/mysql/MySQLGenericPackets.scala +++ b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/mysql/MySQLGenericPackets.scala @@ -54,7 +54,8 @@ object MySQLErrPacket { case kse: KyuubiSQLException if kse.getCause != null => // prefer brief nested error message instead of whole stacktrace apply(kse.getCause) - case e: Exception if e.getMessage contains "NoSuchDatabaseException" => + case e: Exception + if e.getMessage != null && e.getMessage.contains("NoSuchDatabaseException") => MySQLErrPacket(1, MySQLErrorCode.ER_BAD_DB_ERROR, cause.getMessage) case se: SQLException if se.getSQLState == null => MySQLErrPacket(1, MySQLErrorCode.ER_INTERNAL_ERROR, cause.getMessage)