Skip to content

Commit 429084b

Browse files
committed
allow non-Spark classes
1 parent d9754f3 commit 429084b

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

core/src/main/scala/org/apache/spark/util/JsonProtocol.scala

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -920,14 +920,10 @@ private[spark] class JsonProtocol(sparkConf: SparkConf) extends JsonUtils {
920920
case `blockUpdate` => blockUpdateFromJson(json)
921921
case `resourceProfileAdded` => resourceProfileAddedFromJson(json)
922922
case other =>
923-
if (other.startsWith("org.apache.spark")) {
924-
val otherClass = Utils.classForName(other)
925-
if (classOf[SparkListenerEvent].isAssignableFrom(otherClass)) {
926-
mapper.readValue(json.toString, otherClass)
927-
.asInstanceOf[SparkListenerEvent]
928-
} else {
929-
throw new SparkException(s"Unknown event type: $other")
930-
}
923+
val otherClass = Utils.classForName(other)
924+
if (classOf[SparkListenerEvent].isAssignableFrom(otherClass)) {
925+
mapper.readValue(json.toString, otherClass)
926+
.asInstanceOf[SparkListenerEvent]
931927
} else {
932928
throw new SparkException(s"Unknown event type: $other")
933929
}

core/src/test/scala/org/apache/spark/util/JsonProtocolSuite.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,18 +1023,17 @@ class jsonProtocolSuite extends SparkFunSuite {
10231023
))
10241024
}
10251025

1026-
test("SPARK-52381: only read Spark classes") {
1026+
test("SPARK-52381: handle class not found") {
10271027
val unknownJson =
10281028
"""{
10291029
| "Event" : "com.example.UnknownEvent",
10301030
| "foo" : "foo"
10311031
|}""".stripMargin
10321032
try {
10331033
jsonProtocol.sparkEventFromJson(unknownJson)
1034-
fail("Expected SparkException for unknown event type")
1034+
fail("Expected ClassNotFoundException for unknown event type")
10351035
} catch {
1036-
case e: SparkException =>
1037-
assert(e.getMessage.startsWith("Unknown event type"))
1036+
case e: ClassNotFoundException =>
10381037
}
10391038
}
10401039

0 commit comments

Comments
 (0)