On Wed, 6 Sep 2023 18:34:29 GMT, Mandy Chung <[email protected]> wrote:
> This reimplements
> `sun.reflect.ReflectionFactory::newConstructorForSerialization` with method
> handles.
>
> This API currently generates the bytecode which fails the verification
> because `new C; invokespecial A()` where the given class `C` and invoke a
> no-arg constructor of `C`'s first non-`Serializable` superclass `A` is not a
> valid operation per the VM specification. VM special cases the classes
> generated for reflection to skip verification for the constructors generated
> for serialization and externalization. This change will allow such VM hack
> to be removed.
>
> A `jdk.reflect.useOldSerializableConstructor` system property can be set to
> use the old implementation in case if customers run into any compatibility
> issue. I expect this change has very low compatibility risk. This system
> property is undocumented and will be removed in a future release.
src/java.base/share/classes/java/lang/invoke/MethodHandles.java line 3534:
> 3532: * This method is only used to implement the unsupported
> 3533: *
> sun.reflect.ReflectionFactory::newConstructorForSerialization API.
> 3534: */
The following is probably more correct:
Suggestion:
/**
* Produces a method handle that is capable of creating instances of
the given class
* and instantiated by the given constructor. No security manager
check.
*
* This method is used to implement serialization and the unsupported
* sun.reflect.ReflectionFactory::newConstructorForSerialization API.
*/
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/15600#discussion_r1317735916