You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by ho...@apache.org on 2026/09/01 10:09:05 UTC

(spark) branch master updated: [MINOR] Small adjustments in JsonProtocol event decoding

This is an automated email from the ASF dual-hosted git repository.

asf-gitbox-commits pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git


The following commit(s) were added to refs/heads/master by this push:
     new 8866d3830411 [MINOR] Small adjustments in JsonProtocol event decoding
8866d3830411 is described below

commit 8866d383041108d5dd6923aa1611f3e6ef31c246
Author: Holden Karau <ho...@snowflake.com>
AuthorDate: Tue Sep 1 00:51:39 2026 -0700

    [MINOR] Small adjustments in JsonProtocol event decoding
    
    Minor refinement to how unrecognized event names are resolved, plus a
    companion test to pin down the resulting behavior.
    
    
    Co-authored-by: Holden Karau <ho...@pigscanfly.ca>
---
 .../scala/org/apache/spark/util/JsonProtocol.scala |  3 ++-
 .../org/apache/spark/util/JsonProtocolSuite.scala  | 27 ++++++++++++++++++++++
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/core/src/main/scala/org/apache/spark/util/JsonProtocol.scala b/core/src/main/scala/org/apache/spark/util/JsonProtocol.scala
index 5f7ad0dce1f8..2d5a978b49e9 100644
--- a/core/src/main/scala/org/apache/spark/util/JsonProtocol.scala
+++ b/core/src/main/scala/org/apache/spark/util/JsonProtocol.scala
@@ -965,7 +965,8 @@ private[spark] object JsonProtocol extends JsonUtils {
       case `blockUpdate` => blockUpdateFromJson(json)
       case `resourceProfileAdded` => resourceProfileAddedFromJson(json)
       case other =>
-        val otherClass = Utils.classForName(other)
+        // `other` comes from event log content so it may ref unsupported types.
+        val otherClass = Utils.classForName(other, initialize = false)
         if (classOf[SparkListenerEvent].isAssignableFrom(otherClass)) {
           mapper.readValue(json.toString, otherClass)
             .asInstanceOf[SparkListenerEvent]
diff --git a/core/src/test/scala/org/apache/spark/util/JsonProtocolSuite.scala b/core/src/test/scala/org/apache/spark/util/JsonProtocolSuite.scala
index f6d2298a2aba..4639aa4da9dc 100644
--- a/core/src/test/scala/org/apache/spark/util/JsonProtocolSuite.scala
+++ b/core/src/test/scala/org/apache/spark/util/JsonProtocolSuite.scala
@@ -836,6 +836,19 @@ class JsonProtocolSuite extends SparkFunSuite {
     assert(JsonProtocol.sparkEventFromJson(unknownFieldsJson) === expected)
   }
 
+  test("unknown event types are rejected without static initialization") {
+    val eventJson =
+      """{
+        |  "Event" : "org.apache.spark.util.JsonProtocolStaticInitProbe$"
+        |}""".stripMargin
+    val e = intercept[SparkException] {
+      JsonProtocol.sparkEventFromJson(eventJson)
+    }
+    assert(e.getMessage.contains("Unknown event type"))
+    assert(!JsonProtocolStaticInitProbeFlag.triggered,
+      "static initializer of a non-SparkListenerEvent class must not run")
+  }
+
   test("SPARK-42204: spark.eventLog.includeTaskMetricsAccumulators config") {
     val includeConf = new JsonProtocolOptions(
       new SparkConf().set(EVENT_LOG_INCLUDE_TASK_METRICS_ACCUMULATORS, true))
@@ -3241,3 +3254,17 @@ private[spark] object JsonProtocolSuite extends Assertions {
 }
 
 case class TestListenerEvent(foo: String, bar: Int) extends SparkListenerEvent
+
+/** Records whether [[JsonProtocolStaticInitProbe]] has been statically initialized. */
+private[util] object JsonProtocolStaticInitProbeFlag {
+  @volatile var triggered = false
+}
+
+/**
+ * Probe used to verify that JsonProtocol does not run static initializers of classes named by
+ * the Event field. Only ever referenced by (string) name, so that initialization is observable
+ * exclusively through [[JsonProtocolStaticInitProbeFlag]].
+ */
+private[util] object JsonProtocolStaticInitProbe {
+  JsonProtocolStaticInitProbeFlag.triggered = true
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org