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

Enhance identification of special serialization methods

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Withdrawn
    • Icon: P4 P4
    • None
    • 8, 11, 17, 20
    • core-libs
    • None

      Currently, the implementation of serialization makes use of `Class.getDeclaredMethod(String,Class<?>...)` to get a reference to the special serialization "magic" methods, like `writeObject` or `writeReplace`.

      However, this getter fails to return all the methods with the given name and parameter types. More specifically, it returns the one with the most specific return type, or an arbitrary one if no most specific one exists. Consequently, serialization might fail to locate the "magic" methods even if they exists in the class.

      This is not a real problem for java source classes, but might be one for other JVM languages.

      Since there's no `Class.getDeclaredMethod()` variant that accepts an additional `Class<?>` parameter for the return type, one workaround is to use `Class.getDeclaredMethods()` and retrieve the correct one in the returned array.

      Similarly for `Class.getDeclaredField()`.

      Alternatively, a `Class.getDeclaredMethod(String,Class<?>, Class<?>...)` with an additional parameter for the return type could be added to `Class`.

            rgiulietti Raffaello Giulietti
            rgiulietti Raffaello Giulietti
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: