You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "LuciferYang (via GitHub)" <gi...@apache.org> on 2024/02/27 06:12:58 UTC

Re: [PR] [SPARK-47153][CORE] Guard serialize/deserialize in JavaSerializer with try-with-resource block [spark]

LuciferYang commented on code in PR #45238:
URL: https://github.com/apache/spark/pull/45238#discussion_r1503688318


##########
core/src/main/scala/org/apache/spark/serializer/JavaSerializer.scala:
##########
@@ -118,22 +118,24 @@ private[spark] class JavaSerializerInstance(
 
   override def serialize[T: ClassTag](t: T): ByteBuffer = {
     val bos = new ByteBufferOutputStream()
-    val out = serializeStream(bos)
-    out.writeObject(t)
-    out.close()
+    Utils.tryWithResource(serializeStream(bos)) { out =>

Review Comment:
   There should be other similar cases, for example:
   
   https://github.com/apache/spark/blob/1a408033daf458f1ceebbe14a560355a1a2c0a70/core/src/main/scala/org/apache/spark/scheduler/TaskDescription.scala#L92-L94
   
   https://github.com/apache/spark/blob/1a408033daf458f1ceebbe14a560355a1a2c0a70/sql/core/src/main/scala/org/apache/spark/sql/execution/arrow/ArrowConverters.scala#L473
   
   cc @mridulm 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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