Skip to content

Commit ad38533

Browse files
committed
Avoid failing to initCause on JDBC exception with cause initialized to null
1 parent 8c911ad commit ad38533

File tree

1 file changed

+7
-1
lines changed
  • sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/jdbc

1 file changed

+7
-1
lines changed

sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/jdbc/JdbcUtils.scala

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,13 @@ object JdbcUtils extends Logging {
653653
val cause = e.getNextException
654654
if (cause != null && e.getCause != cause) {
655655
if (e.getCause == null) {
656-
e.initCause(cause)
656+
try {
657+
e.initCause(cause)
658+
} catch {
659+
// cause may have been explicitly initialized to null, in which case this
660+
// fails. No way to detect it, can only catch the exception.
661+
case _: IllegalStateException => e.addSuppressed(cause)
662+
}
657663
} else {
658664
e.addSuppressed(cause)
659665
}

0 commit comments

Comments
 (0)