Skip to content
Snippets Groups Projects
Commit 254877c2 authored by Kunal Khamar's avatar Kunal Khamar Committed by Xiao Li
Browse files

[SPARK-20164][SQL] AnalysisException not tolerant of null query plan.

## What changes were proposed in this pull request?

The query plan in an `AnalysisException` may be `null` when an `AnalysisException` object is serialized and then deserialized, since `plan` is marked `transient`. Or when someone throws an `AnalysisException` with a null query plan (which should not happen).
`def getMessage` is not tolerant of this and throws a `NullPointerException`, leading to loss of information about the original exception.
The fix is to add a `null` check in `getMessage`.

## How was this patch tested?

- Unit test

Author: Kunal Khamar <kkhamar@outlook.com>

Closes #17486 from kunalkhamar/spark-20164.
parent a8a765b3
No related branches found
No related tags found
No related merge requests found
......@@ -43,7 +43,7 @@ class AnalysisException protected[sql] (
}
override def getMessage: String = {
val planAnnotation = plan.map(p => s";\n$p").getOrElse("")
val planAnnotation = Option(plan).flatten.map(p => s";\n$p").getOrElse("")
getSimpleMessage + planAnnotation
}
......
......@@ -2598,4 +2598,12 @@ class SQLQuerySuite extends QueryTest with SharedSQLContext {
}
assert(!jobStarted.get(), "Command should not trigger a Spark job.")
}
test("SPARK-20164: AnalysisException should be tolerant to null query plan") {
try {
throw new AnalysisException("", None, None, plan = null)
} catch {
case ae: AnalysisException => assert(ae.plan == null && ae.getMessage == ae.getSimpleMessage)
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment