Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8275392

jdk.unsupported/sun.reflect.ReflectionFactory.readObjectNoDataForSerialization uses wrong signature

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 18
    • core-libs
    • None
    • binary
    • medium
    • Hide
      Prior to the change, code that called this method would have always received null, regardless of the presence of the readObjectNoData method, due to the wrong parameter list used by the implementation. With the change, null is still returned if a readObjectNoData method is not present, otherwise a MethodHandle for the method is returned.

      Existing code that might have adhered to the erroneous specification and invoked the returned MethodHandle with an ObjectInputStream as parameter, will now be executed and throw java.lang.invoke.WrongMethodTypeException.
      Show
      Prior to the change, code that called this method would have always received null, regardless of the presence of the readObjectNoData method, due to the wrong parameter list used by the implementation. With the change, null is still returned if a readObjectNoData method is not present, otherwise a MethodHandle for the method is returned. Existing code that might have adhered to the erroneous specification and invoked the returned MethodHandle with an ObjectInputStream as parameter, will now be executed and throw java.lang.invoke.WrongMethodTypeException.
    • Java API
    • JDK

      Summary

      Correct the method-level specification to align with the signature of the serialization method readObjectNoData,

      private void readObjectNoData() throws ObjectStreamException;

      Problem

      The method that returns the matching handle for readObjectNoData, sun.reflect.ReflectionFactory.readObjectNoDataForSerialization, assumes the erroneous signature readObjectNoData(ObjectInputStream) - note the superfluous parameter.

      Solution

      Update the specification of sun.reflect.ReflectionFactory.readObjectNoDataForSerialization to use the correct parameter list.

      Specification

      jdk.unsupported/share/classes/sun/reflect/ReflectionFactory.java

           /**
            * Returns a direct MethodHandle for the {@code readObjectNoData} method on
            * a Serializable class.
      -     * The first argument of {@link MethodHandle#invoke} is the serializable
      -     * object and the second argument is the {@code ObjectInputStream} passed to
      -     * {@code readObjectNoData}.
      +     * The only argument of {@link MethodHandle#invoke} is the serializable
      +     * object, which {@code readObjectNoData} is called on. No arguments are
      +     * passed to the {@code readObjectNoData} method.
            *
            * @param cl a Serializable class
            * @return  a direct MethodHandle for the {@code readObjectNoData} method
      public final MethodHandle readObjectForSerialization(Class<?> cl) {}

            jboes Julia Boes (Inactive)
            webbuggrp Webbug Group
            Daniel Fuchs
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: