Fangchen Li created SPARK-57596:
-----------------------------------

             Summary: De-reflect ScalaReflection.findConstructor's 
companion-apply fallback
                 Key: SPARK-57596
                 URL: https://issues.apache.org/jira/browse/SPARK-57596
             Project: Spark
          Issue Type: Sub-task
          Components: Spark Core, SQL
    Affects Versions: 4.3.0
            Reporter: Fangchen Li


ScalaReflection.findConstructor resolves how to instantiate a type. It first 
looks for a matching constructor via Java reflection (ConstructorUtils); only 
if none is accessible does it fall back to a companion-object `apply` method, 
which it finds and invokes via scala.reflect (the runtime universe — 
mirror.staticClass(...), universe.TermName("apply")).
 
That fallback is the only scala.reflect.runtime use left among the object's 
codegen utilities. A Scala companion is just a JVM class with a static MODULE$ 
and an `apply` method, so the same lookup is reachable by ordinary Java 
reflection — no runtime universe needed.
 
Proposed: reimplement the fallback with Java reflection. Behavior-preserving on 
2.13.
 
Reference + test (resolves a companion `apply` from a Scala 3 process; confirms 
a matching constructor still takes precedence):
https://github.com/bearing-research/ProtoCatalyst (spark-reflection-patch/, 
FindConstructorFallbackSpec)



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

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

Reply via email to