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

srowen 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 acd5dc499d1 [SPARK-45467][CORE] Replace `Proxy.getProxyClass()` with 
`Proxy.newProxyInstance().getClass`
acd5dc499d1 is described below

commit acd5dc499d139ce8b2571a69beab0f971947adb4
Author: YangJie <yangji...@baidu.com>
AuthorDate: Wed Oct 11 08:49:09 2023 -0500

    [SPARK-45467][CORE] Replace `Proxy.getProxyClass()` with 
`Proxy.newProxyInstance().getClass`
    
    ### What changes were proposed in this pull request?
    This pr replace `Proxy.getProxyClass()` with 
`Proxy.newProxyInstance().getClass` to clean up deprecated api usage ref to
    
    
https://github.com/openjdk/jdk/blob/dfacda488bfbe2e11e8d607a6d08527710286982/src/java.base/share/classes/java/lang/reflect/Proxy.java#L376-L391
    
    ```
         * deprecated Proxy classes generated in a named module are encapsulated
         *      and not accessible to code outside its module.
         *      {link Constructor#newInstance(Object...) 
Constructor.newInstance}
         *      will throw {code IllegalAccessException} when it is called on
         *      an inaccessible proxy class.
         *      Use {link #newProxyInstance(ClassLoader, Class[], 
InvocationHandler)}
         *      to create a proxy instance instead.
         *
         * see <a href="#membership">Package and Module Membership of Proxy 
Class</a>
         * revised 9
         */
        Deprecated
        CallerSensitive
        public static Class<?> getProxyClass(ClassLoader loader,
                                             Class<?>... interfaces)
            throws IllegalArgumentException
    ```
    
    For the `InvocationHandler`, since the `invoke` method  doesn't need to be 
actually called in the current scenario, but the `InvocationHandler` can't be 
null, a new `DummyInvocationHandler` has been added as follows:
    
    ```
    private[spark] object DummyInvocationHandler extends InvocationHandler {
      override def invoke(proxy: Any, method: Method, args: Array[AnyRef]): 
AnyRef = {
        throw new UnsupportedOperationException("Not implemented")
      }
    }
    ```
    
    ### Why are the changes needed?
    Clean up deprecated API usage.
    
    ### Does this PR introduce _any_ user-facing change?
    No
    
    ### How was this patch tested?
    Pass GitHub Actions
    
    ### Was this patch authored or co-authored using generative AI tooling?
    No
    
    Closes #43291 from LuciferYang/SPARK-45467.
    
    Lead-authored-by: YangJie <yangji...@baidu.com>
    Co-authored-by: yangjie01 <yangji...@baidu.com>
    Signed-off-by: Sean Owen <sro...@gmail.com>
---
 .../main/scala/org/apache/spark/serializer/JavaSerializer.scala  | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git 
a/core/src/main/scala/org/apache/spark/serializer/JavaSerializer.scala 
b/core/src/main/scala/org/apache/spark/serializer/JavaSerializer.scala
index 95d2bdc39e1..856e639fcd9 100644
--- a/core/src/main/scala/org/apache/spark/serializer/JavaSerializer.scala
+++ b/core/src/main/scala/org/apache/spark/serializer/JavaSerializer.scala
@@ -18,6 +18,7 @@
 package org.apache.spark.serializer
 
 import java.io._
+import java.lang.reflect.{InvocationHandler, Method, Proxy}
 import java.nio.ByteBuffer
 
 import scala.reflect.ClassTag
@@ -79,7 +80,7 @@ private[spark] class JavaDeserializationStream(in: 
InputStream, loader: ClassLoa
       // scalastyle:off classforname
       val resolved = ifaces.map(iface => Class.forName(iface, false, loader))
       // scalastyle:on classforname
-      java.lang.reflect.Proxy.getProxyClass(loader, resolved: _*)
+      Proxy.newProxyInstance(loader, resolved, DummyInvocationHandler).getClass
     }
 
   }
@@ -88,6 +89,12 @@ private[spark] class JavaDeserializationStream(in: 
InputStream, loader: ClassLoa
   def close(): Unit = { objIn.close() }
 }
 
+private[spark] object DummyInvocationHandler extends InvocationHandler {
+  override def invoke(proxy: Any, method: Method, args: Array[AnyRef]): AnyRef 
= {
+    throw new UnsupportedOperationException("Not implemented")
+  }
+}
+
 private object JavaDeserializationStream {
 
   val primitiveMappings = Map[String, Class[_]](


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

Reply via email to