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/03/28 14:27:40 UTC

Re: [PR] Test compile scala with `-release 17` [spark]

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


##########
core/src/main/scala/org/apache/spark/serializer/SerializationDebugger.scala:
##########
@@ -68,8 +70,13 @@ private[spark] object SerializationDebugger extends Logging {
   }
 
   private[serializer] var enableDebugging: Boolean = {
-    !AccessController.doPrivileged(new sun.security.action.GetBooleanAction(
-      "sun.io.serialization.extendedDebugInfo")).booleanValue()
+    val lookup = MethodHandles.lookup()
+    val clazz = SparkClassUtils.classForName("sun.security.action.GetBooleanAction")
+    val constructor = clazz.getConstructor(classOf[String])
+    val mh = lookup.unreflectConstructor(constructor)
+    val action = mh.invoke("sun.io.serialization.extendedDebugInfo")
+      .asInstanceOf[PrivilegedAction[Boolean]]
+    !AccessController.doPrivileged(action).booleanValue()

Review Comment:
   Use MethodHandle to ensure logical consistency. Considering that `sun.security` is not an exported package, you can also directly use `!JBoolean.getBoolean("sun.io.serialization.extendedDebugInfo")`.



##########
core/src/main/scala/org/apache/spark/serializer/SerializationDebugger.scala:
##########
@@ -68,8 +70,13 @@ private[spark] object SerializationDebugger extends Logging {
   }
 
   private[serializer] var enableDebugging: Boolean = {
-    !AccessController.doPrivileged(new sun.security.action.GetBooleanAction(
-      "sun.io.serialization.extendedDebugInfo")).booleanValue()
+    val lookup = MethodHandles.lookup()
+    val clazz = SparkClassUtils.classForName("sun.security.action.GetBooleanAction")
+    val constructor = clazz.getConstructor(classOf[String])
+    val mh = lookup.unreflectConstructor(constructor)
+    val action = mh.invoke("sun.io.serialization.extendedDebugInfo")
+      .asInstanceOf[PrivilegedAction[Boolean]]
+    !AccessController.doPrivileged(action).booleanValue()

Review Comment:
   Use MethodHandle to ensure logical consistency. Considering that `sun.security` is not an exported package, we can also directly use `!JBoolean.getBoolean("sun.io.serialization.extendedDebugInfo")`.



-- 
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