tkaymak opened a new pull request, #38271: URL: https://github.com/apache/beam/pull/38271
## Summary Replace `(Constructor<X>) X.class.getConstructors()[0]` for `StaticInvoke`, `Invoke`, and `NewInstance` in the shared structured-streaming `EncoderFactory` with a `primaryConstructor()` helper that picks the constructor with the most parameters. `Class.getConstructors()` returns constructors in JVM-defined order that is not guaranteed stable, so resolving the widest constructor explicitly makes the lookup robust to future Spark releases that add overloaded constructors. The downstream `switch (...getParameterCount())` in `invoke(...)` and `newInstance(...)` already dispatches on parameter count, so the widest constructor matches the dispatch table. ## Behavior No-op against currently supported Spark 3 versions: `StaticInvoke`, `Invoke`, and `NewInstance` only have one public constructor each in Spark 3.1.x through 3.5.x, so `getConstructors()[0]` and the widest constructor resolve to the same one. The change is purely defensive. ## Precedent The same fix has already landed in the Spark 4 override in #38255 (commit `9c071c5e`, flagged by Gemini Code Assist round 1). This PR ports it to the shared base so both code paths stay consistent. ## Note on overlap with #38255 #38255 also touches this file at a different line (round-2 fix `a43868508b`, correcting the second `invoke(Expression obj, ...)` switch to key on `INVOKE_CONSTRUCTOR.getParameterCount()` instead of `STATIC_INVOKE_CONSTRUCTOR`). The two changes are independent — this PR can land before or after #38255 and the conflict, if any, is mechanical. ## Test plan - [ ] `./gradlew :runners:spark:3:spotlessCheck` - [ ] `./gradlew :runners:spark:3:test` - [ ] CI green -- 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]
