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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to